zoj1195 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=195 不知道哪错,帮帮忙在下面改改
#include<stdio.h>#include<stdlib.h>intmain(){intn,m,c,i,j,max,a[20],b[40],k,p,q;j=0;w...
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n,m,c,i,j,max,a[20],b[40],k,p,q;
j=0;
while(scanf("%d%d%d",&n,&m,&c)!=EOF)
{
j++;max=0;q=0;
if(n==0&&m==0&&c==0)
break;
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<m;i++)
scanf("%d",&b[i]);
for(i=0;i<m;i++)
{ p=0;
for(k=0;k<i;k++)
if(b[i]==b[k])
p++;
if(p==0)
q=q+a[b[i]-1];
else
q=q-a[b[i]-1];
if(q>max)
max=q;
}
printf("Sequence %d\n",j);
if(max>c)
printf("Fuse was blown.\n\n");
else
printf("Fuse was not blown.\nMaximal power consumption was %d amperes.\n\n",max);
}
system("pause");
return 0;
} 展开
#include <stdlib.h>
int main()
{
int n,m,c,i,j,max,a[20],b[40],k,p,q;
j=0;
while(scanf("%d%d%d",&n,&m,&c)!=EOF)
{
j++;max=0;q=0;
if(n==0&&m==0&&c==0)
break;
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<m;i++)
scanf("%d",&b[i]);
for(i=0;i<m;i++)
{ p=0;
for(k=0;k<i;k++)
if(b[i]==b[k])
p++;
if(p==0)
q=q+a[b[i]-1];
else
q=q-a[b[i]-1];
if(q>max)
max=q;
}
printf("Sequence %d\n",j);
if(max>c)
printf("Fuse was blown.\n\n");
else
printf("Fuse was not blown.\nMaximal power consumption was %d amperes.\n\n",max);
}
system("pause");
return 0;
} 展开
1个回答
展开全部
2处修改
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n,m,c,i,j,max,a[20],b[1000],k,p,q; // b的大小不够,超过40次操作
j=0;
while(scanf("%d%d%d",&n,&m,&c)!=EOF)
{
j++;max=0;q=0;
if(n==0&&m==0&&c==0)
break;
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<m;i++)
scanf("%d",&b[i]);
for(i=0;i<m;i++)
{
p=0;
for(k=0;k<i;k++)
if(b[i]==b[k])
p++;
if(p%2==0) // 用%2来判断是开还是关
q=q+a[b[i]-1];
else
q=q-a[b[i]-1];
if(q>max)
max=q;
}
printf("Sequence %d\n",j);
if(max>c)
printf("Fuse was blown.\n\n");
else
printf("Fuse was not blown.\nMaximal power consumption was %d amperes.\n\n",max);
}
//system("pause");
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n,m,c,i,j,max,a[20],b[1000],k,p,q; // b的大小不够,超过40次操作
j=0;
while(scanf("%d%d%d",&n,&m,&c)!=EOF)
{
j++;max=0;q=0;
if(n==0&&m==0&&c==0)
break;
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<m;i++)
scanf("%d",&b[i]);
for(i=0;i<m;i++)
{
p=0;
for(k=0;k<i;k++)
if(b[i]==b[k])
p++;
if(p%2==0) // 用%2来判断是开还是关
q=q+a[b[i]-1];
else
q=q-a[b[i]-1];
if(q>max)
max=q;
}
printf("Sequence %d\n",j);
if(max>c)
printf("Fuse was blown.\n\n");
else
printf("Fuse was not blown.\nMaximal power consumption was %d amperes.\n\n",max);
}
//system("pause");
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询