UVA 102 Ecological Bin Packing

#include<cstdio>
#include<cstring>
int B1,B2,B3,G1,G2,G3,C1,C2,C3;
char str[6][4]={"BCG","BGC","CBG","CGB","GBC","GCB"};
int an[6]={0};
int main()
{
    while(scanf("%d%d%d%d%d%d%d%d%d",&B1,&G1,&C1,&B2,&G2,&C2,&B3,&G3,&C3)!=EOF)
    {
        int sum=B1+B2+B3+G1+G2+G3+C1+C2+C3;
        an[0]=B1+C2+G3;
        an[1]=B1+C3+G2;
        an[2]=B2+C1+G3;
        an[3]=B3+C1+G2;
        an[4]=B2+C3+G1;
        an[5]=B3+C2+G1;
        int maxi=0;
        for(int i=0;i<6;i++)
            an[maxi]<an[i]?maxi=i:i=i;
        printf("%s %d\n",str[maxi],sum-an[maxi]);
    }
    return 0;
}

你可能感兴趣的:(UVA 102 Ecological Bin Packing)