#include<stdio.h>
#include<string.h>
int main()
{
char a[5];
int t,m,i,c;
scanf("%d",&t);
while(t--)
{
int b=1,s=0;
scanf("%d",&m);
for(i=0;i<m;i++)
{scanf("%s",&a);
if(a[0]=='I')
{ b*=20;
}
else if(a[0]=='S')
{scanf("%d",&c);
s+=c*60/b;
}
else if(a[0]=='O')
{ b/=20;}
}
printf("%d\n",s);
}
return 0;
}
这一题错了好多次 ,改了好多次,自己不细心,题都没看清楚,开始以为24倍,后来发现时20倍了,但改了,输出结果还是0.最后终于找到原因。把程序在该成原来的错的。留个纪念吧!
#include<stdio.h>
#include<string.h>
int main()
{
char a[5];
int t,m,i,c;
scanf("%d",&t);
while(t--)
{
int b=1,s=0;
scanf("%d",&m);
for(i=0;i<m;i++)
{scanf("%s",&a);
if(a[0]=='I')
{ b/=20;
}
else if(a[0]=='S')
{scanf("%d",&c);
s+=c*60*b;
}
else if(a[0]=='O')
{ b*=20;}
}
printf("%d\n",s);
}
return 0;
}
这个思路也是对的,但定义的b整形。除以20后就是0了!错了一点也不冤枉啊!