Brucelee399
Ones'
2017-04-20 14:39

杭电acm1036,为什么wa

  • 杭电
  • acm

附上我的代码以及AC代码

#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
int main()
{
    int n,t,m,ss,flag;
    double d,sum,temp;
    string T;
    cin>>n>>d;
    if(n<1||n>20)return 0;
    if(d<0.0||d>200.0)return 0;
    while(cin>>t)
    {
        sum=0,flag=0;
        for(int i=0;i<n;i++)
          {
              cin>>T;
              if(T=="-:--:--")
              {
                  cout<<setw(3)<<t<<": -"<<endl;
                  flag=1;
                  break;
              }
              sum+=((T[0]-'0')*3600+((T[2]-'0')*10+(T[3]-'0'))*60+(T[5]-'0')*10+(T[6]-'0'));
          }
        if(!flag)
        {
            sum/=d;
            temp=(int)(sum+0.5);
            m=temp/60;
            ss=temp-m*60;
            if(ss>10)
                cout<<setw(3)<<t<<": "<<m<<":"<<ss<<" min/km"<<endl;
            else
                cout<<setw(3)<<t<<": "<<m<<":"<<'0'<<ss<<" min/km"<<endl;
        }
    }
}

AC代码

#include <stdio.h>
#include <math.h>
#include <string.h>
int main()
{
    char s[10];
    int n,H,MM,SS,T;
    double dist,tot,ave;
    scanf("%d%lf",&n,&dist);
    while(~scanf("%d",&T))
    {
        tot = 0.0;
        bool flag = true;
        for(int i = 0;i < n;i++)
        {
            scanf("%s",s);
            if(!strcmp(s,"-:--:--")){
               flag = false;
            }else
            {
               sscanf(s,"%d:%d:%d",&H,&MM,&SS);   
               tot += H*3600.0 + MM*60.0 + SS*1.0;  
            }
        }
        if(flag == false){
          printf("%3d: -\n",T);
        }else
        {
            ave = tot / dist;
            int ans = floor(ave+0.5);
            printf("%3d: %d:%02d min/km\n",T,ans/60,ans%60);
        }
    }
    return 0;
}
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答