代码实现:
#include<stdio.h>
#include<string.h>
int main()
{
char a[101], b[101], z[101];
int flag = 1;
scanf("%s %s", a, b);
if (strlen(b) < strlen(a))
{
for (int j = 0; j < strlen(a) - strlen(b); j++)z[j] = '0';
z[strlen(a) - strlen(b)] = 0;
strcat(z, b); strcpy(b, z);
}
for (int i = strlen(b) - 1, j = strlen(a) - 1; i >= 0 && j >= 0; i--, j--)
{
if (flag == 1)
if ((b[i] - '0' + a[j] - '0') % 13 == 10)b[i] = 'J', flag *= -1;
else if ((b[i] - '0' + a[j] - '0') % 13 == 11)b[i] = 'Q', flag *= -1;
else if ((b[i] - '0' + a[j] - '0') % 13 == 12)b[i] = 'K', flag *= -1;
else b[i] = (b[i] - '0' + a[j] - '0') % 13 + '0', flag *= -1;
else
if (b[i] - a[j] >= 0)b[i] = b[i] - a[j] + '0', flag *= -1;
else b[i] = b[i] - a[j] + 10 + '0',flag*=-1;
}
puts(b);
return 0;
}