解題心得
照著題目敘述寫就好了。
程式碼
#include <iostream>
using namespace std;
int find_table(char c)
{
if(c=='A' || c=='B' || c=='C') return 2;
else if(c=='D' || c=='E' || c=='F') return 3;
else if(c=='G' || c=='H' || c=='I') return 4;
else if(c=='J' || c=='K' || c=='L') return 5;
else if(c=='M' || c=='N' || c=='O') return 6;
else if(c=='P' || c=='Q' || c=='R' || c=='S') return 7;
else if(c=='T' || c=='U' || c=='V') return 8;
else if(c=='W' || c=='X' || c=='Y' || c=='Z') return 9;
}
int main()
{
string s;
while(cin>>s)
{
int capital=0, hyphen=0;
for(int i=0;i<s.length();i++)
{
if(s[i]=='-' || s[i]=='1' || s[i]=='0')
cout<<s[i];
else
cout<<find_table(s[i]);
if(s[i]=='-') hyphen++;
if(isupper(s[i])) capital++;
}
cout<<" "<<capital<<" "<<hyphen<<endl;
}
return 0;
}
沒有留言:
張貼留言