本题超级简单,练习sscanf()使用,练习scanf()中正则表达式:[^ ]写法,练习ceil(),floor()函数用法。
题目链接:http://acm.hit.edu.cn/hoj/problem/view?id=1057
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
char info[200];
char sCity[100];
char dCity[100];
int mile;
char flag;
int acm;
int sum = 0;
while(scanf("%[^\n]s",info)!=EOF)
{
if(strcmp(info,"#") == 0)
{
break;
}
if(strcmp(info,"0") == 0)
{
printf("%d\n",sum);
sum = 0;
}
else
{
sscanf(info,"%s %s %d %c",sCity,dCity,&mile,&flag);
//printf("%s %s %d %c\n",sCity,dCity,mile,flag);
if(flag == 'F')
{
sum += mile * 2;
}
else if(flag == 'B')
{
sum += ceil(mile *1.5);
}
else if(flag == 'Y')
{
if(mile<=500)
{
sum += 500;
}
else
{
sum += mile;
}
}
}
getchar();
//getch();
}
}