题解 | #简单密码#
简单密码
https://www.nowcoder.com/practice/7960b5038a2142a18e27e4c733855dac
#include <cctype>
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char* argv[]) {
string str;
getline(cin, str);
for (int i = 0; i < str.size(); ++i) {
if (str[i] >= 'a' && str[i] <= 'z') {
if (str[i] == 'a' || str[i] == 'b' || str[i] == 'c') {
str[i] = '2';
}
if (str[i] == 'd' || str[i] == 'e' || str[i] == 'f') {
str[i] = '3';
}
if (str[i] == 'g' || str[i] == 'h' || str[i] == 'i') {
str[i] = '4';
}
if (str[i] == 'j' || str[i] == 'k' || str[i] == 'l') {
str[i] = '5';
}
if (str[i] == 'm' || str[i] == 'n' || str[i] == 'o') {
str[i] = '6';
}
if (str[i] == 'p' || str[i] == 'q' || str[i] == 'r' || str[i] == 's') {
str[i] = '7';
}
if (str[i] == 't' || str[i] == 'u' || str[i] == 'v') {
str[i] = '8';
}
if (str[i] == 'w' || str[i] == 'x' || str[i] == 'y' || str[i] == 'z') {
str[i] = '9';
}
}
if (str[i] >= 'A' && str[i] <= 'Z') {
str[i] = tolower(str[i]);
if (str[i] == 'z') {
str[i] = 'a';
} else {
str[i] += 1;
}
}
}
cout << str << endl;
}