题解 | #字符串的反码#
字符串的反码
https://www.nowcoder.com/practice/01b7dae14d1b464db5f9259e90d9a35e
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
string str;
while (cin >> str) {
for (int i = 0; i < str.size(); i++) {
char c = str[i];
if (c >= 'a' && c <= 'z') {
int distance = c - 'a';
c = 'z' - distance;
}
if (c >= 'A' && c <= 'Z') {
int distance = c - 'A';
c = 'Z' - distance;
}
cout << c;
}
cout << endl;
};
}
查看11道真题和解析