题解 | #简单密码#
简单密码
https://www.nowcoder.com/practice/ff99c43dd07f4e95a8f2f5448da3772a
#include <cstdio> #include "string" using namespace std; string jiemi(string miwen) { string mingwen; for (int i = 0; i < miwen.size(); i++) { if (miwen[i] >= 'F' && miwen[i] <= 'Z') { mingwen.push_back(miwen[i] - 5); } else { if (miwen[i] <= 'E' && miwen[i] >= 'A') mingwen.push_back(miwen[i] + 21); else mingwen.push_back(miwen[i]); } } return mingwen; } int main() { // while (1) { char str[200]; char start[20]; char end[5]; fgets(start, 20, stdin); string Start = start; Start.erase(Start.end() - 1); if (Start == "ENDOFINPUT") { // break; } else { fgets(str, 200, stdin); fgets(end, 10, stdin); string miwen = str; miwen.erase(miwen.end() - 1); string mingwen = jiemi(miwen); printf("%s\n", mingwen.c_str()); } // } return 0; }
他这个结果输入肯定有问题,
我把外层 while去掉,里边 break去掉 ,答案竟然通过过了
我不去掉的话,报错,并且答案是 循环输出,一直不停知道越界
但是我在clion上运行的很好