1058. A + B in Hogwarts (20) Time Limit 50 ms memory limit 32000 kb code length limit 16000 B discriminant program standard author Chen, Yue
If you are a fan of Harry Potter, you wocould know the world of magic has its own currency system -- As Hagrid explained it to Harry, "Seventeen silver sickles to a galleon and twenty-nine knuts to a sickle, it's easy enough. "Your job is to write a program
Compute a + B where A and B are given in the standard form of "galleon. Sickle. Knut" (Galleon is an integer in [0, 107], sickle is an integer in [0, 17), and Knut is an integer in [0, 29 )).
Input specification:
Each input file contains one test case which occupies a line with A and B in the standard form, separated by one space.
Output specification:
For each test case you shoshould output the sum of A and B in one line, with the same format as the input.
Sample input:
3.2.1 10.16.27
Sample output:
14.1.28
Recommendation index :※
Source: http://pat.zju.edu.cn/contests/pat-a-practise/1058
Don't think too complicated
#include<iostream>#include<string.h>#include<stdio.h>using namespace std;int main(){long a[3];long b[3];scanf("%ld.%ld.%ld",&a[0],&a[1],&a[2]);scanf("%ld.%ld.%ld",&b[0],&b[1],&b[2]);int tmp;tmp=a[2]+b[2];if(tmp>=29){a[2]=tmp-29;a[1]++;}elsea[2]=tmp;tmp=a[1]+b[1];if(tmp>=17){a[1]=tmp-17;a[0]++;}elsea[1]=tmp;a[0]+=b[0];int i=0;cout<<a[0]<<"."<<a[1]<<"."<<a[2]<<endl;return 0;}