p1089题解
x12345678901 · · 题解
题解
代码在此,天下我有!!!
代码
#include<iostream>
#include<cmath>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<string>
#include<cstdlib>
#define PI 3.141593
using namespace std;
int main(){
int x=0;
int y;
int yh=0;
//初始化
for(int k=1;k<=12;k++){
x+=300;//模拟给钱
cin>>y;//读入花销
x-=y;//计算结余
if(x<0){
cout<<'-'<<k;//输出钱不够
return 0;
}
else{
yh+=x/100;//模拟存银行
x%=100;
}
}
cout<<120*yh+x;//输出,这样写可以规避1.2这个浮点数
return 0;
}
原理
一道简简单单轻轻松松的模拟题,循环模拟12个月,在其中模拟给钱、存钱等操作。
这样写可以规避1.2这个浮点数。因为乘法一项放大100倍,另一项放大