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 ****************************************************************/
#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 ****************************************************************/