版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xr469786706/article/details/87717100
PAT(甲级)渡劫(十八)-A+B in Hogwarts(20)
代码如下:
#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;
}