简单密码.cpp
简单密码
http://www.nowcoder.com/questionTerminal/7960b5038a2142a18e27e4c733855dac
十分简单易懂的代码
#include<iostream> #include<cstdio> #include<string> using namespace std; char UptoLow(char x) { if(x>='A'&&x<='Y')x+=33; else if(x=='Z')x='a'; return x; } char Lowtoint(char x) { char ch; if(x>='a'&&x<='c')ch='2'; else if(x>='d'&&x<='f')ch='3'; else if(x>='g'&&x<='i')ch='4'; else if(x>='j'&&x<='l')ch='5'; else if(x>='m'&&x<='o')ch='6'; else if(x>='p'&&x<='s')ch='7'; else if(x>='t'&&x<='v')ch='8'; else ch='9'; return ch; } int main() { string str; while(cin>>str) { for(int i=0;i<str.size();++i) { if(str[i]>='A'&&str[i]<='Z') str[i]=UptoLow(str[i]); else if(str[i]>='a'&&str[i]<='z') str[i]=Lowtoint(str[i]); } cout<<str<<endl; } return 0; }