POJ 1326 Mileage Bank (,四舍五入法)

来源:互联网 发布:如何数据恢复 编辑:程序博客网 时间:2024/05/18 03:36
AC好久才成功了;学会四舍五入法   例如 int ans=ans+(m(int型)*1.0 / 2.0 + 0.5)话说现在才道这个 string类这么好用;
附上代码Mileage BankTime Limit: 1000MSMemory Limit: 10000KTotal Submissions: 12562Accepted: 5236DescriptionMileage program of ACM (Airline of Charming Merlion) is really nice for the travelers flying frequently. Once you complete a flight with ACM, you can earn ACMPerk miles in your ACM Mileage Bank depended on mileage you actual fly. In addition, you can use the ACMPerk mileage in your Mileage Bank to exchange free flight ticket of ACM in future. The following table helps you calculate how many ACMPerk miles you can earn when you fly on ACM. When you fly ACM Class Code          You'll earn First Class F Actual mileage + 100% mileage Bonus Business Class    B Actual mileage + 50% mileage Bonus Economy Class Y1-500 miles 500 miles500+ miles Actual mileageIt's shown that your ACMPerk mileage consists of two parts. One is your actual flight mileage (the minimum ACMPerk mileage for Economy Class for one flight is 500 miles), the other is the mileage bonus (its accuracy is up to 1 mile) when you fly in Business Class and First Class. For example, you can earn 1329 ACMPerk miles, 1994 ACMPerk miles and 2658 ACMPerk miles for Y, B or F class respectively for the fly from Beijing to Tokyo (the actual mileage between Beijing and Tokyo is 1329 miles). When you fly from Shanghai to Wuhan, you can earn ACMPerk 500 miles for economy class and ACMPerk 650 miles for business class (the actual mileage between Shanghai and Wuhan is 433 miles). Your task is to help ACM build a program for automatic calculation of ACMPerk mileage. InputThe input file contains several data cases. Each case has many flight records, each per line. The flight record is in the following format: OriginalCity DistanceCity ActualMiles ClassCode Each case ends with a line of one zero. A line of one # presents the end of the input file. OutputOutput the summary of ACMPerk mileages for each test case, one per line.Sample InputBeijing Tokyo 1329 FShanghai Wuhan 433 Y0#Sample Output3158HintWhen calculate bonus ,be sure you rounded x.5 up to x+1
----------------------------------------------------------------------------------
#include<iostream>#include<string>using namespace std;int main(){    string str1,str2,str3;    int m;    int ans=0;    while(cin>>str1)    {        if(str1=="0")        {            cout<<ans<<endl;            ans=0;            continue;        }        if(str1=="#") break;        cin>>str2>>m>>str3;        if(str3=="F") ans+=m*2;        if(str3=="B") {ans+=m;ans+=(m*1.0 / 2.0 + 0.5);}        if(str3=="Y") {if(1<=m&&m<=500) ans+=500;else ans+=m;}    }}

原创粉丝点击