Blowing Fuses保险丝问题
1 #include<iostream>
2 #include<string>
3 using namespace std;
4 int main(){
5 int m,n,c,x;
6 int t[20];
7 int v[20];
8 int q=0;
9 while(cin>>m>>n>>c){
10 if(m==0&&n==0&&c==0)break;
11 q++;
12 for(int i=0;i<20;i++){
13 t[i]=v[i]=0;
14 }
15 for(int i=0;i<m;i++)
16 cin>>t[i];
17 int all=0;
18 int max=0;
19 for(int i=0;i<n;i++){
20 cin>>x;
21 if(v[x-1]){
22 v[x-1]=0;
23 all-=t[x-1];
24 }
25 else {
26 v[x-1]=t[x-1];
27 all+=t[x-1];
28 }
29 if(max<all)max=all;
30 }
31 cout<<"Sequence "<<q<<endl;
32 if(all>c){
33
34 cout<<"Fuse was blown."<<endl;
35 }
36 else{
37 cout<<"Fuse was not blown."<<endl;
38 cout<<"Maximal power consumption was "<<max<<" amperes."<<endl;
39 }
40 cout<<endl;
41
42 }
43 }
2 #include<string>
3 using namespace std;
4 int main(){
5 int m,n,c,x;
6 int t[20];
7 int v[20];
8 int q=0;
9 while(cin>>m>>n>>c){
10 if(m==0&&n==0&&c==0)break;
11 q++;
12 for(int i=0;i<20;i++){
13 t[i]=v[i]=0;
14 }
15 for(int i=0;i<m;i++)
16 cin>>t[i];
17 int all=0;
18 int max=0;
19 for(int i=0;i<n;i++){
20 cin>>x;
21 if(v[x-1]){
22 v[x-1]=0;
23 all-=t[x-1];
24 }
25 else {
26 v[x-1]=t[x-1];
27 all+=t[x-1];
28 }
29 if(max<all)max=all;
30 }
31 cout<<"Sequence "<<q<<endl;
32 if(all>c){
33
34 cout<<"Fuse was blown."<<endl;
35 }
36 else{
37 cout<<"Fuse was not blown."<<endl;
38 cout<<"Maximal power consumption was "<<max<<" amperes."<<endl;
39 }
40 cout<<endl;
41
42 }
43 }
逍遥地羊啊。。。。

浙公网安备 33010602011771号