-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1048.cpp
More file actions
34 lines (32 loc) · 783 Bytes
/
Copy path1048.cpp
File metadata and controls
34 lines (32 loc) · 783 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
using namespace std;
const string digit = "0123456789JQK";
int main()
{
string numA, numB, num;
cin >> numA;
cin >> numB;
int i, k = numA.length() - numB.length(), flag(1), temp(0);
if(k>0) {
for( i=0; i<k; ++i )
numB = '0' + numB;
k = numA.length() - numB.length();
}
for( i=numA.length()-1; i>=0; --i ) {
if(flag>0) {
num = digit[( ( numA[i] + numB[i-k] - '0'*2 )%13 )] + num;
}
else {
temp = numB[i-k] - numA[i];
if( temp<0) temp += 10;
num = (char)(temp+'0') + num;
}
flag *= -1;
}
if(k<0) {
for( i=-k-1; i>=0; --i )
num = numB[i] + num;
}
cout << num << endl;
return 0;
}