标签:
#include <iostream> #include <string> #include <vector> using namespace std; int alpha2num(char c) { int num = 0; switch(c) { case '1': num = 1; break; case 'a': case 'b': case 'c': num = 2; break; case 'd': case 'e': case 'f': num = 3; break; case 'g': case 'h': case 'i': num = 4; break; case 'j': case 'k': case 'l': num = 5; break; case 'm': case 'n': case 'o': num = 6; break; case 'p': case 'q': case 'r': case 's': num = 7; break; case 't': case 'u': case 'v': num = 8; break; case 'w': case 'x': case 'y': case 'z': num = 9; break; case '0': num = 0; break; default: num =0; break; } return num; } int main() { string str; vector<char> vec; char ch; while(cin>>str) { for(size_t i = 0; i < str.length(); ++i) { if(str[i]>= 'a' && str[i] <='z') { int num = alpha2num(str[i]); ch = '0' + num; } else if(str[i] >= 'A' && str[i] <='Z') { ch = 'a' +(str[i] - 'A' +1)%26; } else { ch = str[i]; } vec.push_back(ch); } for(size_t i = 0; i < vec.size(); ++i) { cout<<vec[i]; } cout<<endl; } return 0; }
标签:
原文地址:http://blog.csdn.net/xiaohanstu/article/details/45603495