您的位置:首页 > 其它

1037. 在霍格沃茨找零钱(20)

2016-01-28 22:18 225 查看
如果你是哈利·波特迷,你会知道魔法世界有它自己的货币系统 —— 就如海格告诉哈利的:“十七个银西可(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


#include<iostream>

#include<sstream>

#include<string>

using namespace std;

int main()

{

string s1,s2;

cin>>s1>>s2;

int a1,a2,a3;

stringstream ss1,ss2,ss3;

//cout<<s1.substr(0,s1.find('.'))<<endl;

ss1<<s1.substr(0,s1.find('.'));

ss1>>a1;

string temp=s1.substr(s1.find('.')+1,s1.length()-s1.find('.')-1);

//cout<<temp.substr(0,temp.find('.'))<<endl;

ss2<<temp.substr(0,temp.find('.'));

ss2>>a2;

//cout<<temp.substr(temp.find('.')+1,temp.length()-temp.find('.')-1);

ss3<<temp.substr(temp.find('.')+1,temp.length()-temp.find('.')-1);

ss3>>a3;

int b1,b2,b3;

stringstream ssb1,ssb2,ssb3;

ssb1<<s2.substr(0,s2.find('.'));

ssb1>>b1;

temp=s2.substr(s2.find('.')+1,s2.length()-s2.find('.')-1);

ssb2<<temp.substr(0,temp.find('.'));

ssb2>>b2;

ssb3<<temp.substr(temp.find('.')+1,temp.length()-temp.find('.')-1);

ssb3>>b3;

int t1,t2,t;

t1=a3+a2*29+a1*29*17;

t2=b3+b2*29+b1*29*17;

if(t2>=t1)

{

t=t2-t1;

}

else

{

cout<<"-";

t=t1-t2;

}

int m3=t%29;

int m2=t%(29*17)/29;

int m1=t/(29*17);

cout<<m1<<"."<<m2<<"."<<m3;

return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: