PAT1048
程序员文章站
2022-07-15 13:40:35
...
#include<iostream>
#include <iomanip>
#include <cstdio>
#include<string>
#include<vector>
#include<array>
#include<math.h>
#include <ctype.h>
#include<algorithm>
using namespace std;
int main()
{
string a, b,c;
cin >> a >> b;
int i,temp;
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
int l1 = a.length();
int l2 = b.length();
char str[14] = { "0123456789JQK" };
if (l1 > l2)
b.append(l1 - l2, '0');
else
a.append(l2 - l1, '0');
for (i = 0; i < a.length(); i++)
{
if (i % 2 == 0)
{
c += str[(a[i] - '0' + b[i] - '0') % 13];
}
else
{
temp = b[i] - a[i];
if (temp < 0)
temp = temp + 10;
c += str[temp];
}
}
reverse(c.begin(), c.end());
cout << c;
return 0;
}
上一篇: PAT1056
下一篇: PAT 乙级 1056 组合数的和