注意:个位为第一位
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
string a, b, c;
cin >> a >> b;
int lena = a.length(), lenb = b.length();
//首先将a和b倒置,将字符串a和b中较短的那个末尾添加0直到两个字符串长度相等
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
if (lena > lenb) b.append(lena - lenb, '0');
else a.append(lenb - lena, '0'); //在后面补'0'
char str[14] = {"0123456789JQK"};
for (int i = 0; i < a.length(); i++) {
if (i % 2 == 0) //奇数位
c += str[(a[i] - '0' + b[i] - '0') % 13];
else { //偶数位
int temp = b[i] - a[i];
if (temp < 0) temp = temp + 10;
c += str[temp];
}
}
for (int i = c.length() - 1; i >= 0; i--) //倒序输出
cout << c[i];
return 0;
}