2024年7月14日
我写了一些代码
但是十分烂
so,能帮我优化吗?代码如下:
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int hm = 0, a, b = 1, d = 0;
for(int i = 1; i <= 12; i ++){
int ys;
cin >> ys;
hm += 300;
if((hm - ys) / 100 > 0){
d += (hm - ys) / 100 * 100;
hm -= (hm - ys) / 100 * 100;
}
if(hm < ys){
a = i;
b = 0;
break;
}
hm -= ys;
}
if(b == 0){
cout << "-" << a;
}else{
cout << hm + d * 120 / 100;
}
return 0;
}