Run ID:104646
提交时间:2025-01-05 21:09:16
#include <iostream> using namespace std; int main() { string password; cin >> password; // 输入六位数字密码 // 确保输入的密码长度为 6 位 if (password.length()!= 6) { cout << "请输入六位数字密码" << endl; return 0; } // 第一个字符为密码第一个数字所对应的大写字母 char firstChar = 'A' + (password[0] - '0'); // 第二个字符根据密码第二个数字的奇偶性进行处理 char secondChar; if ((password[1] - '0') % 2 == 0) { secondChar = ((password[1] - '0') / 2) + '0'; } else { secondChar = password[1]; } // 前三个数字相加的个位数字 int sumFirstThree = (password[0] - '0') + (password[1] - '0') + (password[2] - '0'); char thirdChar = (sumFirstThree % 10) + '0'; // 第四个字符为密码第四个数字本身 char fourthChar = password[3]; // '乐'字拼音中,每一个字符(小写)所对应的 ASCII 相加再加上第五位密码的所得值的十位 int leSum = 'l' + 'e'; int fifthCharValue = (((leSum + (password[4] - '0')) / 10) % 10); char fifthChar = fifthCharValue + '0'; // 全部六个密码数字相加的个位 int sumAll = 0; for (int i = 0; i < 6; i++) { sumAll += (password[i] - '0'); } char sixthChar = (sumAll % 10) + '0'; // 输出加密后的密码 cout << firstChar << secondChar << thirdChar << fourthChar << fifthChar << sixthChar << endl; return 0; }