POJ 1326 Mileage Bank(私の水題の道--シミュレーション、四捨五入)


Mileage Bank
Time Limit: 1000MS
 
Memory Limit: 10000K
Total Submissions: 11620
 
Accepted: 4824
Description
Mileage 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			 Y

1-500 miles					 500 miles

500+ miles					 Actual mileage

It'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. 
Input
The 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. 
Output
Output the summary of ACMPerk mileages for each test case, one per line.
Sample Input
Beijing Tokyo 1329 F
Shanghai Wuhan 433 Y
0
#

Sample Output
3158

Hint
When calculate bonus ,be sure you rounded x.5 up to x+1
Source
Beijing 2002
ある航空会社では、一人の飛行距離を計算する必要があり、飛行タイプはF、B、Yに分けられ、Fの場合、計算された距離は実際の距離の2倍で、タイプがBの場合、計算された距離は実際の距離の1.5倍で、タイプがYの場合、距離が500未満の場合、計算された距離は500で、500より大きい場合、実際の距離を計算します.
解題方法は純粋なシミュレーションである.
注意点:
1)Hintで述べたように,四捨五入が必要である.(int)(num+0.5)を用いて計算した.結果1 WA
コード(1 AC 1 WA):
#include <cstdio>
#include <cstdlib>
#include <cstring>

int main(void){
    int mileage, summileage;
    char cla;
    char from[100], to[100];

    summileage = 0;
    while (scanf("%s", from), strcmp(from, "#") != 0){
        if(strcmp(from, "0") == 0){
            printf("%d
", summileage); summileage = 0; continue; } scanf("%s %d %c
", to, &mileage, &cla); if (cla == 'F'){ summileage += mileage * 2; } else if (cla == 'B'){ summileage += (int)(mileage * 1.5 + 0.5); } else if (cla == 'Y'){ if (mileage < 500){ summileage += 500; } else{ summileage += mileage; } } } return 0; }