Fork me on GitHub

PAT(甲级)渡劫(十八)-A+B in Hogwarts(20)


PAT(甲级)渡劫(十八)-A+B in Hogwarts(20)

代码如下:

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
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
#include <cstdio>
#include <bits/stdc++.h>

using namespace std;

int main(){
//freopen("in.txt","r",stdin);
char s1[30],s2[30];
int a[5],b[5];
scanf("%s%s",s1,s2);
char *result = NULL;
result = strtok(s1,".");
int cnt1 = 0;
while(result != NULL){
a[cnt1++] = atoi(result);
result = strtok(NULL,".");
}

result = NULL;
result = strtok(s2,".");
int cnt2 = 0;
while(result != NULL){
b[cnt2++] = atoi(result);
result = strtok(NULL,".");
}

int ans,tmp;
int c[5],cnt3 = 0;
for(int i = 2 ; i >= 0 ; i--){
if(i == 2){
ans = (a[i] + b[i])%29;
tmp = (a[i]+b[i])/29;
c[cnt3++] = ans;
}else if(i == 1){
ans = (a[i] + b[i] + tmp)%17;
tmp = (a[i] + b[i] + tmp)/17;
c[cnt3++] = ans;
}else{
ans = (a[i] + b[i] + tmp);
c[cnt3++] = ans;
}
}
cout<<c[2]<<"."<<c[1]<<"."<<c[0]<<endl;
return 0;
}

运行结果:

坚持原创技术分享,您的支持将鼓励我继续创作
-------------本文结束感谢您的阅读-------------
0%