题解 | #简单密码#
简单密码
http://www.nowcoder.com/practice/7960b5038a2142a18e27e4c733855dac
好像题解里面都没有用case 'a' ... 'c':
这种语法,写起来直观又简单
#include <iostream>
using namespace std;
int main() {
string str;
cin >> str;
for (int i=0; i<str.size(); i++) {
switch(str[i]) {
case 'A' ... 'Y': str[i] += 33; break;
case 'Z': str[i] = 'a'; break;
case 'a' ... 'c': str[i] = '2'; break;
case 'd' ... 'f': str[i] = '3'; break;
case 'g' ... 'i': str[i] = '4'; break;
case 'j' ... 'l': str[i] = '5'; break;
case 'm' ... 'o': str[i] = '6'; break;
case 'p' ... 's': str[i] = '7'; break;
case 't' ... 'v': str[i] = '8'; break;
case 'w' ... 'z': str[i] = '9'; break;
default: break;
}
}
cout << str << endl;
}