為何我自己測都過 , 放上去測都是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" ;
}
}