Sample Input
1 2 3 4 5 6 7 8 9 5 10 5 20 10 5 10 20 10
Sample Output
BCG 30 CBG 50
#include<stdio.h>
#include<string.h>
void main()
{
int a[3][3],i,j,t,b[6]={0},k=0,d=0;
char c[6][4]={"BGC","BCG","GBC","GCB","CBG","CGB"},s[4];
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
scanf("%d",&a[i][j]);
d=d+a[i][j];
}
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
if(j==i)continue;
for(t=0;t<3;t++)
{
if(t==j||t==i)continue;
b[k]=d-a[0][i]-a[1][j]-a[2][t];
k++;
}
}
k=232;
for(i=0;i<6;i++)
{
if(b[i]==0)continue;
if(b[i]<k)k=b[i],strcpy(s,c[i]);
else if(b[i]==k&&strcmp(s,c[i])>0)strcpy(s,c[i]);
}
printf("%s %d
",s,k);
}