| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
水过,帖代码,供借鉴#include<iostream>
using namespace std;
int main(void )
{
int n,arry[21],m,c,i;
int total,j;
int flag,k;
int count=0;
int kd[100][2];
for(k = 0;k<100;k++)
{
kd[k][0]=0;
kd[k][1]=0;
}
while(1)
{
total = 0;
flag =0;
k = 0;
cin>>n>>m>>c;
if(n==0&&m==0&&c==0)
break;
for(i=0;i<n;i++)
cin>>arry[i];
for(i = 0;i<m;i++)
{ cin>>j;
total = total +arry[j-1];
if(total<=c&&total>k){//这个判断很重要!!!!
k = total;
kd[count][1]=k;
}
arry[j-1]=-arry[j-1];
if(total>c){
flag=-1;
kd[count][0]=-1;
}
}
count ++;
}
/////////////////////////////
for(i =0;i<count;i++){
cout<<"Sequence "<<i+1<<endl;
if(kd[i][0]==-1){
cout<<"Fuse was blown."<<endl<<endl;
continue;
}
else
{
cout<<"Fuse was not blown."<<endl;
cout<<"Maximal power consumption was "<<kd[i][1]<<" amperes."<<endl<<endl;
}
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator