题目链接
- 一开始我还以为以b的长度为基准,因为b是要加密的数据啊,看了答案才知道原来要以最长的长度为基准。
- 但是这道题还有个bug,就是当你算出的结果前面有0竟然也可以通过,比如a为1111,b为1111,答案是0202这种情况也可以通过,还以为必须是202呢,当然202也可以通过。这两种情况竟然都能通过,一个输入竟然可以有两个输出,神奇。
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include<vector>
#include<map>
#include <string>
using namespace std;int main() {string a, b;vector<char>res;vector<char> c = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' ,'J' ,'Q' ,'K' };cin >> a >> b;reverse(a.begin(), a.end());reverse(b.begin(), b.end());if (b.size() > a.size()) {a.append(b.size() - a.size(), '0');}else {b.append(a.size() - b.size(), '0');}int result;int i;for (i = 0; i < b.size(); i++) {if (i % 2 == 0) {//奇数的情况result = (b[i] - '0' + a[i] - '0') % 13;res.push_back(c[result]);}else {//偶数的情况result = b[i] - a[i];if (result < 0)result = result + 10;res.push_back(result + '0');}}reverse(res.begin(), res.end());for (i = 0; i < res.size(); i++) {if (res[i] != '0')break;}for (int j = i; j < res.size(); j++) {cout << res[j];}cout << endl;return 0;
}复制代码