Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
104512 | 王子毅 | 11加密规则 | C++ | Wrong Answer | 1 MS | 276 KB | 1651 | 2025-01-05 11:41:27 |
#include <iostream> #include <string> using namespace std; string encryptPassword(string password) { if (password.length()!= 6) { throw invalid_argument("输入必须是六位数字"); } string encrypted = ""; // 第一个字符为密码第一个数字所对应的大写字母 encrypted += char('A' + (password[0] - '0')); // 第二个字符按照密码第二个数字的奇偶性进行处理,偶数除以2,奇数不处理 if ((password[1] - '0') % 2 == 0) { encrypted += to_string((password[1] - '0') / 2); } else { encrypted += password[1]; } // 第三个字符为密码前三个数字相加的个位数字 int thirdDigit = (password[0] - '0' + password[1] - '0' + password[2] - '0') % 10; encrypted += to_string(thirdDigit); // 第四个字符即为密码第四个数字本身 encrypted += password[3]; // 第五个字符则为'乐'(le)字拼音中,每一个字符(小写)所对应的 ASCII 相加再加上第五位密码的所得值的十位 int leAsciiSum = 'l' + 'e'; int fifthDigit = (leAsciiSum + (password[4] - '0')) / 10; encrypted += to_string(fifthDigit); // 第六个字符则是全部六个密码数字相加的个位 int totalSum = 0; for (char c : password) { totalSum += c - '0'; } encrypted += to_string(totalSum % 10); return encrypted; } int main() { string password; cin >> password; try { cout << encryptPassword(password) << endl; } catch (const invalid_argument& e) { cerr << e.what() << endl; } return 0; }
------Input------
115209
------Answer-----
B17208
------Your output-----
B172208