如果你是哈利·波特迷,你会知道魔法世界有它自己的货币系统 —— 就如海格告诉哈利的:“十七个银西可(Sickle)兑一个加隆(Galleon),二十九个纳特(Knut)兑一个银西可,很容易。”现在,给定哈利应付的价钱 P 和他实付的钱 A,你的任务是写一个程序来计算他应该被找的零钱。
输入格式:
输入在 1 行中分别给出 P 和 A,格式为 Galleon.Sickle.Knut
,其间用 1 个空格分隔。这里 Galleon
是 [0, 107] 区间内的整数,Sickle
是 [0, 17) 区间内的整数,Knut
是 [0, 29) 区间内的整数。
输出格式:
在一行中用与输入同样的格式输出哈利应该被找的零钱。如果他没带够钱,那么输出的应该是负数。
输入样例 1:
10.16.27 14.1.28
输出样例 1:
3.2.1
输入样例 2:
14.1.28 10.16.27
输出样例 2:
-3.2.1
分析:
将输入的x.y.z类型的数据转为Knut
然后相减,再转为x.y.z即可
1 //c++
2
3 #include<iostream>
4 #define SICKLE 17
5 #define KNUT 29
6 using namespace std;
7
8 void func(char *s,long &a,int &b,int &c);
9 int main(){
10 char P[30],A[30];
11 cin>>P>>A;
12 long p1,a1;
13 int p2,p3,a2,a3;
14 func(P,p1,p2,p3);
15 func(A,a1,a2,a3);
16 long sum1=p1*SICKLE*KNUT+p2*KNUT+p3;
17 long sum2=a1*SICKLE*KNUT+a2*KNUT+a3;
18 long sub=sum2-sum1;
19 if(sub==0)
20 cout<<"0.0.0";
21 else{
22 if(sub<0){
23 sub=-sub;
24 cout<<'-';
25 }
26 long res1,res2,res3;
27 res1=sub/(SICKLE*KNUT);
28 res2=(sub-res1*SICKLE*KNUT)/KNUT;
29 res3=sub-res1*SICKLE*KNUT-res2*KNUT;
30 cout<<res1<<'.'<<res2<<'.'<<res3;
31 }
32 }
33 void func(char *s,long &a,int &b,int &c){
34 long digit=0;
35 int i=0;
36 while(s[i]!='.')
37 digit=digit*10+s[i++]-'0';
38 a=digit;
39 digit=0;
40 i++;
41 while(s[i]!='.')
42 digit=digit*10+s[i++]-'0';
43 b=digit;
44 digit=0;
45 i++;
46 while(s[i]!='