题解 | #简单密码#
简单密码
https://www.nowcoder.com/practice/7960b5038a2142a18e27e4c733855dac
按照题目要求一步步的实现
/**
* @file hj21-简单密码.cc
* @author (malixian)
* @brief 大写变小写,然后后移一位;小写变数字;数字不变
* @version 0.1
* @date 2022-08-11
*
* @copyright Copyright (c) 2022
*
*/
#include <iostream>
#include <string>
using namespace std;
void mima()
{
string str;
getline(cin, str);
for (auto &c : str) {
if (isupper(c)) { // 大写转小写,小写后移动一位
c = tolower(c);
if (c != 'z') {
c = c + 1;
} else {
c = 'a';
}
continue;
// 小写转数字
} else if ('a' <= c && c <= 'c') {
c = '2';
} else if ('d' <= c && c <= 'f') {
c = '3';
} else if ('g' <= c && c <= 'i') {
c = '4';
} else if ('j' <= c && c <= 'l') {
c = '5';
} else if ('m' <= c && c <= 'o') {
c = '6';
} else if ('p' <= c && c <= 's') {
c = '7';
} else if ('t' <= c && c <= 'v') {
c = '8';
} else if ('w' <= c && c <= 'z') {
c = '9';
}
}
cout << str << endl;
}
int main()
{
mima();
return 0;
}
迅雷公司福利 193人发布