jasonshen_ @ 2023-03-14 22:52:25
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
int main(){
float all;
cin>>all;
float ans=1;
if(all<=150){
ans=all*0.4463;
}
if(all>=151&&all<=400){
ans=150*0.4463;
all=all-150;
ans=ans+all*0.4663;
}
if(all>=401){
ans=150*0.4463;
all=all-150;
ans=ans+all*0.4663;
all=all-249;
ans=ans+all*0.5663;
}
cout<<fixed<<setprecision(1)<<ans;
return 0;
}
by manyc @ 2023-03-19 21:10:38
不用这么复杂,有些部分可以直接用常数代替
#include<iostream>
#include<iomanip>
using namespace std;
int main(){
int n;
cin>>n;
if(n<=150) cout<<fixed<<setprecision(1)<<double(n)*0.4463;
else if(n<=400) cout<<fixed<<setprecision(1)<<(150.0*0.4463)+(double(n-150)*0.4663);
else cout<<fixed<<setprecision(1)<<(150.0*0.4463)+(250.0*0.4663)+(double(n-400)*0.5663);
return 0;
}