题目1484:Mileage Bank
来源:互联网 发布:白虹软件 编辑:程序博客网 时间:2024/05/24 05:05
题目描述:
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 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.
- 输入:
he 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 the summary of ACMPerk mileages for each test case, one per line.
- 样例输入:
Beijing Tokyo 1329 FShanghai Wuhan 433 Y0#
- 样例输出:
3158
- 提示:
When calculate bonus ,be sure you rounded x.5 up to x+1
一直AC不过,但感觉逻辑上没有问题?实在不知错在何处。自己写的比较麻烦,找到一个网上的解法,写得比较简洁,而且四舍五入处值得借鉴。
#include<stdio.h>#include<string.h>#include<math.h>#include<string>using namespace std;char str[100];int main() {int sum = 0;while (gets(str)) {if (strlen(str) == 1 && str[0] == '0') {printf("%d\n", sum);sum = 0;continue;}if (strlen(str) == 1 && str[0] == '#')break;string s = str;int pos1 = s.find(' ', 0);int pos2 = s.find(' ', pos1 + 1);int pos3 = s.find(' ', pos2 + 1);double num = 0;//int num = 0;for (int i = pos2 + 1; i < pos3; i++)num = num * 10 + (s[i] - '0');char flag = s[pos3 + 1];if (flag == 'F')sum += num * 2;else if (flag == 'B')sum += round(num * 3 / 2);//sum += num + (num + 1) / 2;else {if (num <= 500)sum += 500;elsesum += num;}}return 0;}
#include<iostream>using namespace std;int main() {char ch;string s;int m, n = 0;while (cin >> s) {if (s == "#")break;else if (s == "0") {cout << n << endl;n = 0;} else {cin >> s >> m >> ch;if (ch == 'F')n += 2 * m;else if (ch == 'B')n += m + (m + 1) / 2; //四舍五入else if (ch == 'Y' && m <= 500)n += 500;elsen += m;}}return 0;}
题目链接:
http://ac.jobdu.com/problem.php?pid=1484
- 题目1484:Mileage Bank
- 题目1484:Mileage Bank
- 九度oj 题目1484:Mileage Bank
- 【九度】题目1484:Mileage Bank
- 内存超出 题目1484:Mileage Bank
- Mileage Bank
- Mileage Bank
- pku1326 - Mileage Bank
- FZU 1116 Mileage Bank
- POJ 1326 Mileage Bank
- poj1326(Mileage Bank)
- POJ 1326 Mileage Bank
- zoj 1365 Mileage Bank
- POJ1326浅析------Mileage Bank
- poj 1326 Mileage Bank
- ZOJ 1365 Mileage Bank
- 1326 Mileage Bank
- Hoj 1057 Mileage Bank
- 树莓派搭建虚拟渗透网站Bwapp
- Struts2中的OGNL详解
- MyBatis Generator Mybatis代码生成介绍
- 2017-02-11号 图解TCP/IP协议 第6章 TCP与UDP
- Android Studio值得推荐的Oblivion主题背景
- 题目1484:Mileage Bank
- IO流学习小结(二)
- 磁盘问题定位与解决
- Spring Cloud中,Eureka常见问题总结
- freemarker遍历jav数组和map
- [Android Studio 权威教程]断点调试和高级调试
- 内部类
- [BZOJ 1202][HNOI2005]狡猾的商人(并查集+前缀和)
- 九度OJ学习笔记 题目1054