#17456: ?


moulin878@gmail.com (林莫莫)

學校 : 不指定學校
編號 : 81816
來源 : [223.137.113.90]
最後登入時間 :
2021-09-17 21:22:22
b981. YoJudge 預練(時間之章) -- b961YoJudge | From: [140.122.107.162] | 發表日期 : 2019-04-12 20:38

為何我自己測都過 , 放上去測都是0???

 

#include <iostream>
#include <cstring>
#include <cstdlib>
using namespace std;
int main()
{
char str[100];
double h;
double m;
double s;
double ms;
while(cin >> str)
{
int i=0;
int j=0;
int time=0;
while(str[i])
{
char num[100];
if(isdigit(str[i]) || str[i] == '.')
{
num[j] = str[i];
i++;
j++;
}
else if(str[i]=='h')
{
num[j] = '\0';
h = atof(num);
time += h*60*60*1000;
j=0;
i++;
}
else if(str[i]=='m')
{
if(str[i+1]=='s')
{
num[j] = '\0';
ms = atof(num);
time += ms;
i+=2;
j=0;
break;
}
num[j] = '\0';
m = atof(num);
time += m*60*1000;
i++;
j=0;
}
else if(str[i]=='s')
{
num[j] = '\0';
s = atof(num);
time += s*1000;
i++;
j=0;
}
else
{
i++;
}
}
cout << time << "\n" ;
}
}

 
ZeroJudge Forum