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.
Output the summary of ACMPerk mileages for each test case, one per line. When calculate bonus, be sure you rounded x.5 up to x+1
Beijing Tokyo 1329 F Shanghai Wuhan 433 Y 0 #
3158
#include <stdio.h> #include <string.h> #define N 1000 int GetBonus(char str[N]) { int len=strlen(str); char c=str[len-1]; int x=0; int i=0; while(str[i]<'0'||str[i]>'9') i++; while('0'<=str[i]&&str[i]<='9') { x=x*10+(str[i]-'0'); i++; } if(c=='F') return 2*x; else if(c=='Y') return x<500 ? 500 : x; else return (int)((double)x*1.5+0.5); } int main() { char str[N]; int mileage; while(gets(str)) { int len=strlen(str); if(str[0]=='0'&&len==1) break; mileage=GetBonus(str); while(gets(str)) { len=strlen(str); if(str[0]=='0'&&len==1) break; mileage+=GetBonus(str); } printf("%d\n", mileage); } return 0; }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int ACMPerk=0; while (scanner.hasNext()){ String s = scanner.nextLine(); if (!s.equals("0")){ String[] s1 = s.split(" "); String level = s1[s1.length-1]; int mile = Integer.parseInt(s1[s1.length-2]); switch (level){ case "F": ACMPerk+= mile*2; break; case "B": ACMPerk+= mile*1.5; break; case "Y": ACMPerk += Math.max(mile, 500); break; } } } System.out.println(ACMPerk); } }
#include<iostream> #include<string> using namespace std; int money(int n, char ch) { switch (ch) { case 'Y': if (n > 500) return n; else return 500; case 'B': return (int)(1.5*n+0.5); case 'F': return 2*n; } return 0; } int main() { string p1, p2; int distance; char rank; int total = 0; while (cin >> p1) { if (p1 == "0") break; cin >> p2 >> distance >> rank; total += money(distance, rank); } cout << total << endl; }
bool process() { int sum = 0; int bonus = 0; std::string src, dst, lv; while ((std::cin >> src) && src != "#") { if (src == "0") { printf("%d\n", sum); return true; } std::cin >> dst >> bonus >> lv; switch(lv[0]) { case 'F': bonus *= 20; break; case 'B': bonus *= 15; break; default : bonus = std::max(bonus, 500) * 10; break; } sum += (bonus + 5) / 10; } return false; }
#include<iostream> (720)#include<string> using namespace std; int main(){ string from,to,level; int len; float sum=0; while(cin>>from){ if(from=="0")break; cin>>to>>len>>level; if(level=="Y"){ if(len<=500)sum+=500; else sum+=len; }else if(level=="B"){ if(len%2==0){ sum+=(len+len/2); }else{ sum+=(len+len/2+1); } }else{ sum+=2*len; } } cout<<sum<<endl; return 0; }
def Mileage(a, b): if b == 'F': return 2*a elif b == 'B': return int(a + 0.5*a + 0.5) elif b == 'Y' and a >= 500: return a else: return 500 s1 = 0 while True: s = list(input().split()) if s[0] == '0'&nbs***bsp;s[0] == '#': break s1+=Mileage(int(s[2]), s[-1]) print(s1)
#include<stdio.h> #include<string> using namespace std; typedef struct Node{ string from; string to; float length; char rank; }Node; int main(){ char tmp1[100] = {0}; char tmp2[100] = {0}; int tmp3; char tmp4; int res = 0; while(scanf("%s%s%d %c",tmp1,tmp2,&tmp3,&tmp4)!=EOF){ if(tmp1[0] =='0'){ printf("%d\n",res); res = 0; }else if(tmp1[0]=='#') break; if(tmp4 == 'F'){ res = res + tmp3*2; }else if(tmp4 =='Y'){ if(tmp3>500){ res = res +tmp3; }else res = res + 500; }else if(tmp4 == 'B'){ res = res + tmp3*1.5; } } }
#include <iostream> #include <string> #include <vector> #include <cmath> using namespace std; int main(){ vector<string> input; string first; while((getline(cin, first)) && first != "#"){ input.push_back(first); string temp; while(input.back()!="0"){ getline(cin, temp); input.push_back(temp); } input.pop_back(); int total = 0; for(int i=0; i<input.size(); ++i){ int mile = 0; for(int j=input[i].size()-3, k=0; input[i][j]>='0' && input[i][j]<='9'; --j, ++k){ mile+=(input[i][j]-'0')*pow(10, k); } if(input[i].back() == 'F'){ total += mile * 2; }else if(input[i].back() == 'B'){ total += ceil(mile * 1.5); // 向上取整 }else if(mile<500){ total += 500; }else { total += mile; } } cout << total << endl; } }
/* 题目翻译: 描述: ACM(魅力鱼尾狮航空公司)的里程计划对经常飞行的旅客来说真的很好。 使用ACM完成飞行后,您可以根据实际飞行里程在ACM里程库中赚取ACMPerk里程。 此外,您可以使用里程银行中的ACMPerk里程在未来兑换ACM的免费机票。 下表帮助您计算在ACM上飞行时可以赚取多少ACMPerk里程。 当您飞行ACM等级代码时, 您将获得头等舱F实际里程+100%里程奖金商务舱B实际里程 +50%里程奖金经济舱Y 1-500英里500英里500英里以上实际里程 据显示,您的ACMPerk里程由两部分组成。 一个是您的实际飞行里程(经济舱一次飞行的最低ACMPerk里程为500英里), 另一个是商务舱和头等舱飞行时的里程奖励(其准确性高达1英里)。 例如,从北京飞往东京的航班, Y、B或F级可分别获得1329 ACMPerk里程、1994 ACMPerk英里和2658 ACMPerk公里 (北京和东京之间的实际里程为1329英里)。 当您从上海飞往武汉时,经济舱可获得500英里的ACMPerk里程, 商务舱可获得650英里的ACMPenk里程(上海和武汉之间的实际里程为433英里)。 您的任务是帮助ACM建立一个自动计算ACMPerk里程的程序。 输入描述: 输入文件包含几个数据案例。每个病例都有许多飞行记录,每一行都有。航班记录的格式如下: 原始城市 距离城市 实际里程 分类代码 每种情况都以一行零结束。 输出描述: 输出每个测试用例的ACMPerk里程摘要,每行一个。 计算奖金时,请确保将x.5四舍五入到x+1 */ #include <iostream> #include <string> using namespace std; int money(int n, char ch) { switch (ch) { case 'Y': if (n > 500) return n; else return 500; case 'B': return (int)(1.5 * n + 0.5); case 'F': return 2 * n; } return 0; } int main() { string p1, p2; int distance; char rank; int total = 0; while (cin >> p1) { if (p1 == "0") break; cin >> p2 >> distance >> rank; total += money(distance, rank); } cout << total << endl; return 0; }
#include <stdio.h> int money(int n,char x) { switch(x){ case 'Y': {if(n>500) { return n; } else { return 500;} } case 'B': { return (int)(1.5*n+0.5); } case 'F': {return 2*n;} } } int main() { char str1[9999],str2[9999],str3[9999]; char p; int n; int sum; sum=0; while(scanf("%s",str1)) { if(str1[0]=='0') { break; } scanf("%s",str2); scanf("%d",&n); scanf("%s",str3); sum+=money(n,*str3); } printf("%d",sum); return 0; }函数指针好烦呀QAQ
#include<iostream> #include<string> #include<math.h> using namespace std; int Mile(int x) {return x>500?x:500; } int main() {string x,y,z;int a;int sum=0; while(cin>>x) {if(x=="0"){break;} cin>>y>>a>>z; if(z=="F"){sum+=Mile(a)*2;} else if(z=="B"){sum+=ceil(Mile(a)*1.5);} else if(z=="Y"){sum+=Mile(a);} } cout<<sum<<endl; return 0; }
#include <iostream> #include <string> #include <math.h> #include <map> using namespace std; map<char,int> Class; double calculate(int dis,int Rank){ if(Rank==0){ if(dis<500)return 500; else return dis; } else if(Rank==1){ return ceil(dis*1.5); } else if(Rank==2){ return ceil(dis*2.0); } } int main() { string info; Class['Y']=0,Class['B']=1,Class['F']=2; int ans=0; while(getline(cin,info)){ if(info=="0")break; int secondBlank = info.find(" ",info.find(" ",0)+1); int thirdBlank = info.find(" ",info.find(" ",info.find(" ",0)+1)+1); string dis = info.substr(secondBlank+1,thirdBlank-secondBlank-1); string Rank = info.substr(info.size()-1,1); ans+=calculate(stoi(dis),Class[Rank[0]]); } cout<<ans<<endl; return 0; }
#include <cstdio> #include <cstring> #include <algorithm> #include <iostream> #include <vector> #include <map> #include <cmath> #include <set> #include <queue> using namespace std; int main() { string s; while(cin >> s) { double ans = 0.0; string t; int x; string tmp; cin >> t >> x >> tmp; if(tmp[0] == 'F') { ans += 2.0*x; } else if(tmp[0] == 'B') { ans += 1.5*x; } else if(tmp[0] == 'Y') { if(x>=500) ans += 1.0*x; else ans += 500.0; } while(cin >> s) { if(s == "0") break; cin >> t >> x >> tmp; if(tmp[0] == 'F') { ans += 2.0*x; } else if(tmp[0] == 'B') { ans += 1.5*x; } else if(tmp[0] == 'Y') { if(x>=500) ans += 1.0*x; else ans += 500.0; } } if(ans - (1.0*((int)ans)) > 0) cout << (((int)ans)+1) <<endl; else cout <<(int)ans << endl; } }
#include<iostream> #include<string> using namespace std; int main() { string str1,str2; char ch; int sum = 0,n; cin >> str1; while(str1 != "0")//判断是否结束输入 { cin >> str2 >> n >> ch; switch(ch)//对ch进行判断选择不同的计算方式 { case 'F': sum += (2 * n);break; case 'B':sum += (int)(n * 1.5 + 0.5);break;// case 'Y':if (n > 500) sum += n; else sum += 500; break; } cin >> str1; } cout << sum <<endl; return 0; }
#include<iostream> #include<cstring> using namespace std; int mile, sum, flag = 1; string c1, c2; char cl; void cal(int mile, char Class) { switch (Class){ case 'F': sum += 2 * mile; break; case 'B': sum += mile * 1.5; if (mile % 2 != 0) sum++; break; case 'Y': if (mile > 500) sum += mile; else sum += 500; break; } } int main() { while (cin >> c1){ if (c1 == "0"){ cout << sum << endl; sum = 0; continue; } cin >> c2 >> mile >> cl; cal(mile,cl); } return 0; }
#!/usr/bin/python #-*- coding:utf-8 -*- #Author: Ben import math def getACMPerk(num, sym): rlt = 0 if sym == 'Y': if num < 500: rlt = 500 else: rlt = num elif sym == 'B': rlt = num + int(math.ceil(num/2.0)) else: rlt = num*2 return rlt first = True while first: rlt = 0 while True: line = raw_input().strip() if line == '#': first = False break if line == '0': print rlt break c1, c2, num, sym = line.split() rlt += getACMPerk(int(num), sym)