poj1484 Blowing Fuses

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

void main(){
    int num,operation_num,max,capacity,curr,i,count=0,total;
    int device_Ampere[30];
    char flag;
    char device_Flag[30];
    scanf("%d %d %d",&num,&operation_num,&capacity);
    while(num != 0 && operation_num != 0 && capacity != 0){
        flag='0';
        max=0;
        total=0;
        for(i=1;i<=num;i++){
            scanf("%d",&device_Ampere[i]);
        }
        memset(device_Flag,'0',sizeof(device_Flag));
        for(i=0;i<operation_num;i++){
            scanf("%d",&curr);
            if(device_Flag[curr] == '0'){
                total+=device_Ampere[curr];
                if(total>capacity)
                    flag='1';
                if(total>max)
                    max=total;
                device_Flag[curr]='1';
            }
            else{
                total-=device_Ampere[curr];
                device_Flag[curr]='0';
            }            
        }
        count++;
        printf("Sequence %d\n",count);    
        if(flag=='1')
            printf("Fuse was blown.\n\n");
        else{
            printf("Fuse was not blown.\n");
            printf("Maximal power consumption was %d amperes.\n\n",max);
        }
        scanf("%d %d %d",&num,&operation_num,&capacity);    
    }
}
您的支持将鼓励我继续创作!