好久没有做到这么简单的题目了,比起下午的Poker Hands
真是有天壤之别。
#include<stdio.h>
#include <string.h>
void solve(int n,int m,int c)
{
int ca[21],de[21],i,total = 0,max = 0,flag = 0 ;
for (i = 1; i <= n; i++ )
{
scanf("%d",& ca[i]);
de[i] = -1 ;
}
for (i = 0; i < m; i++ )
{
int op;
scanf("%d",& op);
de[op] = 0 - de[op];
total += ca[op] * de[op];
if (flag == 0 && total > c)
{
printf("Fuse was blown. " );
flag = 1 ;
}
if (max < total) max = total;
}
if (flag == 0 )
printf("Fuse was not blown./nMaximal power consumption was %d amperes./n" ,max);
}
void main()
{
#ifndef ONLINE_JUDGE
freopen("1195.txt","r" ,stdin);
#endif
int n,m,c,t = 0 ;
while (scanf("%d%d%d",&n,&m,&c) != EOF && !(n == 0 && m == 0 && c == 0 ))
{
printf("Sequence %d ",++ t);
solve(n,m,c);
printf("/n" );
}
#ifndef ONLINE_JUDGE
fclose(stdin);
#endif
}
#include <string.h>
void solve(int n,int m,int c)
{
int ca[21],de[21],i,total = 0,max = 0,flag = 0 ;
for (i = 1; i <= n; i++ )
{
scanf("%d",& ca[i]);
de[i] = -1 ;
}
for (i = 0; i < m; i++ )
{
int op;
scanf("%d",& op);
de[op] = 0 - de[op];
total += ca[op] * de[op];
if (flag == 0 && total > c)
{
printf("Fuse was blown. " );
flag = 1 ;
}
if (max < total) max = total;
}
if (flag == 0 )
printf("Fuse was not blown./nMaximal power consumption was %d amperes./n" ,max);
}
void main()
{
#ifndef ONLINE_JUDGE
freopen("1195.txt","r" ,stdin);
#endif
int n,m,c,t = 0 ;
while (scanf("%d%d%d",&n,&m,&c) != EOF && !(n == 0 && m == 0 && c == 0 ))
{
printf("Sequence %d ",++ t);
solve(n,m,c);
printf("/n" );
}
#ifndef ONLINE_JUDGE
fclose(stdin);
#endif
}