題目鏈接
- 一開始我還以為以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;
}復制代碼