题目链接
坑点
当A的长度大于B A:0000123 B:1 这种形式
实现
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int main(int argc, char** argv) {
string A,B;
cin>>A>>B;
int lenA=strlen(A.c_str());
int lenB=strlen(B.c_str());
if(lenB>=lenA)
{
int len=lenB-lenA;
int i=0;
if(lenA%2==0 && len==0 && A[i]==B[i])
i=1;
for(i;i<lenB;i++)
{
if(i<len)
cout<<B[i];
else
{
int numA=A[i-len]-'0';
int numB=B[i]-'0';
int pos=lenB-i;
int num;
if(pos%2==0)
{
num=numB-numA;
if(num<0)
num+=10;
cout<<num;
}
else
{
num=(numA+numB)%13;
if(num==10)
cout<<"J";
else if(num==11)
cout<<"Q";
else if(num==12)
cout<<"K";
else
cout<<num;
}
}
}
}
else
{
int len=lenA-lenB;
for(int i=0;i<lenA;i++)
{
int pos=lenA-i;
int num,numA,numB,j=0;
if(i<len)
{
if(pos%2==0)
{
if(A[i]-'0' == 0)
cout<<0;
else
{
num=0-(A[i]-'0')+10;
cout<<num;
}
}
else
{
cout<<A[i]-'0';
}
}
else
{
numA=A[i]-'0';
numB=B[i-len]-'0';
if(pos%2==0)
{
num=numB-numA;
if(num<0)
num+=10;
cout<<num;
}
else
{
num=(numA+numB)%13;
if(num==10)
cout<<"J";
else if(num==11)
cout<<"Q";
else if(num==12)
cout<<"K";
else
cout<<num;
}
}
}
}
return 0;
}