本文主要是介绍PAT(BASIC)1037. 在霍格沃茨找零钱(20),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
代码确实有点冗长,请见谅。#include<iostream>
struct money{int Galleon;int Sickle;int Kunt;
};
int main(void){using namespace std;money should_pay,pay,resault;char c;cin>>should_pay.Galleon>>c>>should_pay.Sickle>>c>>should_pay.Kunt>>pay.Galleon>>c>>pay.Sickle>>c>>pay.Kunt;if((pay.Galleon>should_pay.Galleon)||((pay.Galleon>=should_pay.Galleon)&&pay.Sickle>should_pay.Sickle)||(pay.Galleon>=should_pay.Galleon&&pay.Sickle>=should_pay.Sickle&&pay.Kunt>=should_pay.Kunt)){int jw=0;if(pay.Kunt>=should_pay.Kunt)resault.Kunt=pay.Kunt-should_pay.Kunt;else{jw=1;resault.Kunt=pay.Kunt+29-should_pay.Kunt;}pay.Sickle-=jw;jw=0;if(pay.Sickle>=should_pay.Sickle)resault.Sickle=pay.Sickle-should_pay.Sickle;else{jw=1;resault.Sickle=pay.Sickle+17-should_pay.Sickle;}pay.Galleon-=jw;resault.Galleon=pay.Galleon-should_pay.Galleon;cout<<resault.Galleon<<'.'<<resault.Sickle<<'.'<<resault.Kunt;}else{int jw=0;if(should_pay.Kunt>=pay.Kunt)resault.Kunt=should_pay.Kunt-pay.Kunt;else{jw=1;resault.Kunt=should_pay.Kunt+29-pay.Kunt;}should_pay.Sickle-=jw;jw=0;if(should_pay.Sickle>=pay.Sickle)resault.Sickle=should_pay.Sickle-pay.Sickle;else{jw=1;resault.Sickle=should_pay.Sickle+17-pay.Sickle;}should_pay.Galleon-=jw;resault.Galleon=should_pay.Galleon-pay.Galleon;cout<<'-'<<resault.Galleon<<'.'<<resault.Sickle<<'.'<<resault.Kunt;}system("pause");
}
这篇关于PAT(BASIC)1037. 在霍格沃茨找零钱(20)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!