C++ 简单粗暴的解法,只用到了string
#include <iostream>
using namespace std;
#include<string>
int main()
{
int nsize;
char temp;
string str;
while(cin>>str)
{
nsize=str.size();
for(int i=0;i<nsize;i++)
{
if(str[i]>='a'&&str[i]<='z')//小写的转化
{
if(str[i]>='a'&&str[i]<='c')
{
temp='2';
}
else if(str[i]>='d'&&str[i]<='f')
{
temp='3';
}
else if(str[i]>='g'&&str[i]<='i')
{
temp='4';
}
else if(str[i]>='j'&&str[i]<='l')
{
temp='5';
}
else if(str[i]>='m'&&str[i]<='o')
{
temp='6';
}
else if(str[i]>='p'&&str[i]<='s')
{
temp='7';
}
else if(str[i]>='t'&&str[i]<='v')
{
temp='8';
}
else if(str[i]>='w'&&str[i]<='z')
{
temp='9';
}
str[i]=temp;
}
if(str[i]>='A'&&str[i]<'Z')//大写的转化
{
str[i]=str[i]+'a'-'A'+1;
}
else if(str[i]=='Z')
{
str[i]='a';
}
}
cout<<str<<endl;
}
}
京公网安备 11010502036488号