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

题目要求当输入为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;
}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-05
  • 2022-01-11
  • 2022-01-13
  • 2022-01-14
猜你喜欢
  • 2021-09-09
  • 2021-08-25
  • 2021-12-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案