ZOJ 1195 Blowing Fuses

简单题,不说

注意输出后面有. WA了好几次,细节啊细节

Blowing Fuses
   
     
#include < iostream >
using namespace std;

struct device
{
int consume;
int clicktimes;
};
int main()
{
device a[
20 ];
int n, m, c;
int b;
int max = 0 ;
int current = 0 ;
int count = 0 ;

// freopen("test.txt", "r", stdin);

while ( cin >> n >> m >> c && ! (n == 0 && m == 0 && c == 0 ))
{
for ( int i = 0 ; i < n; i ++ )
{
cin
>> a[i].consume;
a[i].clicktimes
= 0 ;
}

for ( int j = 0 ; j < m; j ++ )
{
cin
>> b;
(a[b
- 1 ]).clicktimes ++ ;
if (a[b - 1 ].clicktimes % 2 == 1 )
current
+= a[b - 1 ].consume;
else
current
-= a[b - 1 ].consume;
if (max < current)
max
= current;
}

if (max <= c)
{
printf(
" Sequence %d\nFuse was not blown.\nMaximal power consumption was %d amperes.\n\n " , ++ count, max);
}
else
printf(
" Sequence %d\nFuse was blown.\n\n " , ++ count);
max
= current = 0 ;


}
return 0 ;
}

 

你可能感兴趣的:(ZOJ)