PAT1048
程序员文章站
2022-07-15 13:36:44
...
#include <bits/stdc++.h>
using namespace std;
int main() {
string A,B;
cin>>A>>B;
if(A.size()>B.size())
{
string tmp = "";
for(int i = 0;i<A.size()-B.size();i++) tmp += "0";
B = tmp + B;
}
else if(A.size()<B.size())
{
string tmp = "";
for(int i = 0;i<B.size()-A.size();i++) tmp += "0";
A = tmp + A;
}
int i = A.size()-1;
int site = 1;
char c1,c2;
string ans = "";
while(i>=0)
{
c1 = A[i];
c2 = B[i];
if(site%2)
{
int t = ((c1-'0') + (c2-'0'))%13;
if(t == 10) ans.push_back('J');
else if(t == 11) ans.push_back('Q');
else if(t == 12) ans.push_back('K');
else ans.push_back(t+'0');;
}
else
{
int t = (c2-'0')-(c1-'0');
if(t<0) t+=10;
ans.push_back(t+'0');
}
i--;
site++;
}
reverse(ans.begin(),ans.end());
cout<<ans<<endl;
return 0;
}
/**
1234567 368782971
**/
上一篇: PAT1048 数字加密(20)
下一篇: Pat1048 数字加密 (20 分)