解题思路: Else-if太麻烦了!
先存数组,弄个循环,在循环里判断一下,符合条件就计算答案,不符合条件就退出循环
注意事项:
参考代码:
#include<bits/stdc++.h> using namespace std; int level[7] = {0, 100000, 200000, 400000, 600000, 1000000}; double w[7] = {0.1, 0.075, 0.05, 0.03, 0.015, 0.01}; int main () { double m; cin >> m; double tem = m, ans = 0.0; for(int i = 5; i >= 0; i--) { if(tem > level[i]) { ans += (tem - level[i]) * w[i]; tem = level[i]; } } printf("%.2f",ans); return 0; }
0.0分
0 人评分