ZOJ Problem Set - 1365 Mileage Bank

时间:2022-02-12 20:21:56

题目不难,主要说下这道题目在输入终止上的问题:

题目要求当输入为0时一次case结束,当输入为#时整个输入全部结束,可以用如下格式解决

while(scanf("%s",str)!=EOF&&strcmp(str,"#"))
{
if(!strcmp(str,""))
{
//做出相应处理
continue;
}
}

见ac代码

#include <cstdio>
#include <cstring>
#include <math.h>
#include <iostream> using namespace std; int main()
{
int mile;
char type[],str1[],str2[];
double sum=;
while(scanf("%s",str1)!=EOF&&strcmp(str1,"#"))
{
if(!strcmp(str1,""))
{
printf("%.0lf\n",sum);
sum=;
continue;
}
scanf("%s%d%s",str2,&mile,&type); if(!strcmp(type,"Y"))
sum+=(mile<?:mile);
else if(!strcmp(type,"B"))
sum+=(mile+mile*0.5);
else
sum+=(mile*); sum=ceil(sum);
} return ;
}