請問各位為什麼同一個程式碼跑出來的結果有時候RE,有時候WA(而且WA錯的行數還不一樣)??
可以幫我看看哪裡有問題嗎?
#include<stdio.h>
#include<string.h>
int main()
{
int n,m,temp,flag,k=1;
int c,amp,max;
while(scanf("%d%d%d",&n,&m,&c)==3)
{
if(n==0 && m==0 && c==0) break;
amp=0,max=0,flag=1;
int a[n+1];
int b[n+1];
memset(b,0,sizeof(b));
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
for(int i=0;i<m;i++)
{
scanf("%d",&temp);
b[temp]=(b[temp]+1)%2;
if(b[temp])
{
amp+=a[temp];
if(amp>c)
{
printf("Sequence %d\nFuse was blown.\n\n",k);
flag=0;
break;
}
if(amp>max) max=amp;
}
else amp-=a[temp];
}
if(flag) printf("Sequence %d\nFuse was not blown.\nMaximal power consumption was %d amperes.\n\n",k,max);
k++;
}
return 0;
}
請問各位為什麼同一個程式碼跑出來的結果有時候RE,有時候WA(而且WA錯的行數還不一樣)??
可以幫我看看哪裡有問題嗎?
#include
#include
int main()
{
int n,m,temp,flag,k=1;
int c,amp,max;
while(scanf("%d%d%d",&n,&m,&c)==3)
{
if(n==0 && m==0 && c==0) break;
amp=0,max=0,flag=1;
int a[n+1];
int b[n+1];
memset(b,0,sizeof(b));
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
for(int i=0;i<m;i++)
{
scanf("%d",&temp);
b[temp]=(b[temp]+1)%2;
if(b[temp])
{
amp+=a[temp];
if(amp>c)
{
printf("Sequence %d\nFuse was blown.\n\n",k);
flag=0;
break;
}
if(amp>max) max=amp;
}
else amp-=a[temp];
}
if(flag) printf("Sequence %d\nFuse was not blown.\nMaximal power consumption was %d amperes.\n\n",k,max);
k++;
}
return 0;
}
我知道哪裡錯了,可是還是覺得怪怪的
理論上錯誤訊息應該要一樣吧,為什麼會跳來跳去的??