UVa 102 – Ecological Bin Packing solution in C language

**Before watching this make sure that you’ve tried enough**

#include<stdio.h>

int main()
{
    long int a[7],b[5],c[5],g[5],i,sm;

    while(scanf("%ld%ld%ld%ld%ld%ld%ld%ld%ld",&b[1],&g[1],&c[1],&b[2],&g[2],&c[2],&b[3],&g[3],&c[3]) == 9){

        a[1] = b[2] + b[3] + g[1] + g[2] + c[1] + c[3];
        a[2] = b[2] + b[3] + g[1] + g[3] + c[1] + c[2];
        a[3] = b[1] + b[3] + g[1] + g[2] + c[2] + c[3];
        a[4] = b[1] + b[2] + g[1] + g[3] + c[2] + c[3];
        a[5] = b[1] + b[3] + g[2] + g[3] + c[1] + c[2];
        a[6] = b[1] + b[2] + g[2] + g[3] + c[1] + c[3];

        sm = a[1];
        for(i = 2;i < 7;i++){
            if(a[i] < sm)
                sm = a[i];
        }
        for(i = 1;i < 7;i++){
            if(a[i]==sm){
                if(i == 1)printf("BCG %ld\n",sm);
                else if(i == 2)printf("BGC %ld\n",sm);
                else if(i == 3)printf("CBG %ld\n",sm);
                else if(i == 4)printf("CGB %ld\n",sm);
                else if(i == 5)printf("GBC %ld\n",sm);
                else printf("GCB %ld\n",sm);
                break;
            }
        }
    }
    return 0;
}

 

If this solution helped you, please share this with your friends.
And if you have anything to say, let me know in the comment section.
More solutions are coming so Like our Facebook page and Subscribe to our YouTube channel to stay connected.

Leave a Comment