ZOJ Problem Set - 1365 Mileage Bank
题目不难,主要说下这道题目在输入终止上的问题:
题目要求当输入为0时一次case结束,当输入为#时整个输入全部结束,可以用如下格式解决
while(scanf("%s",str)!=EOF&&strcmp(str,"#")) { if(!strcmp(str,"0")) { //做出相应处理 continue; } }
见ac代码
#include <cstdio> #include <cstring> #include <math.h> #include <iostream> using namespace std; int main() { int mile; char type[10],str1[100],str2[100]; double sum=0; while(scanf("%s",str1)!=EOF&&strcmp(str1,"#")) { if(!strcmp(str1,"0")) { printf("%.0lf\n",sum); sum=0; continue; } scanf("%s%d%s",str2,&mile,&type); if(!strcmp(type,"Y")) sum+=(mile<500?500:mile); else if(!strcmp(type,"B")) sum+=(mile+mile*0.5); else sum+=(mile*2); sum=ceil(sum); } return 0; }