POJ 1326 Mileage Bank(我的水题之路——模拟,四舍五入)
来源:互联网 发布:ziprar解压软件下载 编辑:程序博客网 时间:2024/05/16 09:18
Mileage Bank
Time Limit: 1000MS Memory Limit: 10000KTotal 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.
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.
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 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.
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 FShanghai Wuhan 433 Y0#
Sample Output
3158
Hint
When calculate bonus ,be sure you rounded x.5 up to x+1
Source
Beijing 2002
有一个航空公司,需要计算一个人的飞行里程,飞行类型分为F、B、Y,为F是时,计算的里程为实际里程的两倍,当类型为B时,计算的里程为实际里程的1.5倍,当类型为Y时,如果里程小于500,则计算的里程就为500,如果大于500,则计算实际里程。
解题方法为纯模拟。
注意点:
1)Hint中提到的,需要四舍五入。用(int)(num+0.5),计算得到。导致1WA
代码(1AC1WA):
#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\n", summileage); summileage = 0; continue; } scanf("%s %d %c\n", 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;}
- POJ 1326 Mileage Bank(我的水题之路——模拟,四舍五入)
- poj 1326 Mileage Bank【四舍五入】
- POJ 1326 Mileage Bank (,四舍五入法)
- POJ 1326 Mileage Bank(水~)
- POJ 1326 Mileage Bank
- POJ 1326 Mileage Bank
- poj 1326 Mileage Bank
- POJ 1326 Mileage Bank
- POJ 1326 Mileage Bank 笔记
- POJ 3077 Rounders(我的水题之路——高精度四舍五入)
- POJ 1326 Mileage Bank
- POJ 2390 Bank Interest(我的水题之路——double和floa计算差别)
- 1326 Mileage Bank
- POJ 2562 Primary Arithmetic(我的水题之路——模拟加法进位)
- Mileage Bank
- Mileage Bank
- pku1326 - Mileage Bank
- FZU 1116 Mileage Bank
- 九度oj1188
- 2012童话新年win7主题
- PHP时钟显示
- 走近新加坡-------个人所得税
- 设定Android SDK Home
- POJ 1326 Mileage Bank(我的水题之路——模拟,四舍五入)
- 回车符号和换行符号产生背景
- 两种方法 Find inorder succ of BST
- 美国总统柯立芝曾经写道:“世界上没有一样东西可以取代毅力。才干也不可以枣怀才不遇者比比皆是,一事无成的天才也到处可见;教育也不可以,世界上充斥着学而无用、学非所用的人;只有毅力和决心,才能无往而不胜。
- Finally in Java 及其机制的讨论
- Linux下任务调度的crond常驻命令
- bubble sort in linked list....(java version)
- 建造者(Builder)模式
- 走进美国------个人所得税