【九度】题目1484:Mileage Bank
来源:互联网 发布:阵面网络和云母组关系 编辑:程序博客网 时间:2024/05/14 06:59
题目1484:Mileage Bank
时间限制:1 秒内存限制:128 兆特殊判题:否提交:261解决:91
题目描述:
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.
输入:
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 F
Shanghai Wuhan 433 Y
0
#
样例输出:
3158
提示:
When calculate bonus ,be sure you rounded x.5 up to x+1
来源:
2012年北京大学计算机研究生机试真题
【解题思路】
简单题,仔细读题目大意。
C++ AC
时间限制:1 秒内存限制:128 兆特殊判题:否提交:261解决:91
题目描述:
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.
输入:
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 F
Shanghai Wuhan 433 Y
0
#
样例输出:
3158
提示:
When calculate bonus ,be sure you rounded x.5 up to x+1
来源:
2012年北京大学计算机研究生机试真题
【解题思路】
简单题,仔细读题目大意。
Java AC
import java.util.Scanner;import java.util.regex.Pattern; public class Main { /* * 1484 * 2014年5月30日17:04:12 */ public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNextLine()) { String currLine = scanner.nextLine(); if (currLine.equals("#")) { break; } int finalMiles = 0; while (!currLine.equals("0")) { String array[] = currLine.split(Pattern.quote(" ")); int actualMiles = Integer.parseInt(array[2]); String claCode = array[3]; if (claCode.equals("F")) { finalMiles += actualMiles * 2; } else if (claCode.equals("B")){ finalMiles += actualMiles + (actualMiles%2 == 0 ? actualMiles/2 : actualMiles/2 + 1); } else if (claCode.equals("Y")){ finalMiles += (actualMiles >= 1 && actualMiles <= 500) ? 500 : actualMiles; } currLine = scanner.nextLine(); } System.out.println(finalMiles); } }}/************************************************************** Problem: 1484 User: wangzhenqing Language: Java Result: Accepted Time:230 ms Memory:26504 kb****************************************************************/
C++ AC
#include <string.h>#include <stdio.h>const int maxn=1010;const int maxLen = 20;char origin[maxLen];char dest[maxLen];char flag[maxLen];int finalMiles;int actualMiles; int getAatualMiles(int actualMiles,char flag[]){ if(flag[0] == 'F'){ return actualMiles * 2; } if(flag[0] == 'B'){ int tempMiles = actualMiles % 2 == 0 ? actualMiles / 2 : actualMiles / 2 + 1; return tempMiles + actualMiles; } if(flag[0] == 'Y'){ return (actualMiles >= 1 && actualMiles <= 500) ? 500 : actualMiles; }} int main(){ while(scanf("%s",&origin) != EOF){ if(origin[0] == '#')break; if(origin[0] == '0'){ printf("%d\n",finalMiles); finalMiles = 0; continue; } scanf("%s",&dest); scanf("%d",&actualMiles); scanf("%s",&flag); finalMiles += getAatualMiles(actualMiles, flag); } return 0;}/************************************************************** Problem: 1484 User: wangzhenqing Language: C++ Result: Accepted Time:10 ms Memory:1020 kb****************************************************************/
0 0
- 九度oj 题目1484:Mileage Bank
- 【九度】题目1484:Mileage Bank
- 题目1484:Mileage Bank
- 题目1484:Mileage Bank
- 内存超出 题目1484:Mileage Bank
- Mileage Bank
- Mileage Bank
- 九度oj 题目1454:Piggy-Bank
- 九度题目1454:Piggy-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
- jQuery匿名函数定义
- 行为模式之访问者模式-VISITOR
- IOS 学习基础。
- poj 2778 DNA Sequence ac机+矩阵快速幂
- [LeetCode]Linked List Cycle II
- 【九度】题目1484:Mileage Bank
- 颇有收获发布会体验——LG 电视“决胜画质”系列产品
- oracle常用设置
- Unable to instantiate org.apache.hadoop.hive.metastore.HiveMetaStoreClient错误解决方法
- ARMv8 Linux内核异常处理过程分析
- uboot
- JAVA数据库连接方式汇总
- 职场中表示你该充电的信号
- php中 数组转xml