1058 A+B in Hogwarts (20 分)
If you are a fan of Harry Potter, you would 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 to compute A+B where A and B are given in the standard form of Galleon.Sickle.Knut (Galleon is an integer in [0], Sickle is an integer in [0, 17), and Knut is an integer in [0, 29)).
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 should output the sum of A and B in one line, with the same format as the input.
3.2.1 10.16.27
Sample Output:
14.1.28加一下就可以。
1 #include <bits/stdc++.h>
2
3 using namespace std;
4 string s,ss;
5 int a[
4],b[
4],c[
4];
6 int main(){
7 cin >> s >>
ss;
8 s +=
'.';
9 ss +=
'.';
10 // cout << s << " " << ss << endl;
11 int an =
0;
12 int pos =
0;
13 for(
int i =
0; i < s.length(); i++
){
14 if(s[i] !=
'.'){
15 an = an*
10 + s[i] -
'0';
16 }
else{
17 a[pos++] =
an;
18 an =
0;
19 }
20 }
21 pos =
0;
22 an =
0;
23 for(
int i =
0; i < ss.length(); i++
){
24 if(ss[i] !=
'.'){
25 an = an*
10 + ss[i] -
'0';
26 }
else{
27 b[pos++] =
an;
28 an =
0;
29 }
30 }
31 // cout << a[0]<<" "<<a[1]<<" "<<a[2]<<endl;
32 // cout << b[0]<<" "<<b[1]<<" "<<b[2]<<endl;
33 int flag =
0, flag1 =
0;
34 for(
int i =
2; i >=
0; i--
){
35 if(i ==
2){
36 c[i] = (a[i] + b[i])%
29;
37 flag = (a[i] + b[i])/
29;
38 }
else if(i ==
1){
39 c[i] = (a[i] + b[i] + flag)%
17;
40 flag1 = (a[i] + b[i] + flag)/
17;
41 }
else{
42 c[i] = (a[i] + b[i] + flag1)%
100000001;
43 }
44 }
45 for(
int i=
0; i <
3; i++
){
46 printf(
"%d%c", c[i], i ==
2?
'\n':
'.' );
47 }
48
49 return 0;
50 }
转载于:https://www.cnblogs.com/zllwxm123/p/11190799.html