UVA 102 : https://uva.onlinejudge.org/external/1/102.pdf
/*simulation*/
#include <iostream>
#include<string.h>
using namespace std;
int main() {
const string ans[6]={"BCG","BGC","CBG","CGB","GBC","GCB"};
int num[9],cal[6];
memset(num,0,sizeof(num));
memset(cal,0,sizeof(cal));
while(cin>>num[0])
{
for(int c=1;c<9;c++)
cin>>num[c];
//only move need to calculate
cal[0]=num[3]+num[6]+num[2]+num[8]+num[1]+num[4];//bcg
cal[1]=num[3]+num[6]+num[1]+num[7]+num[2]+num[5];//bgc
cal[2]=num[5]+num[8]+num[0]+num[6]+num[1]+num[4];//cbg
cal[3]=num[5]+num[8]+num[1]+num[7]+num[0]+num[3];//cgb
cal[4]=num[4]+num[7]+num[0]+num[6]+num[2]+num[5];//gbc
cal[5]=num[4]+num[7]+num[2]+num[8]+num[0]+num[3];//gcb
int min=0, _ans=0,m =0;
min=cal[0];
for(;m<6;m++)
{
if(min>cal[m]){
min=cal[m];
_ans=m;
}
}
cout<<ans[_ans]<<" "<<min<<endl;
}
return 0;
}
/*simulation*/
#include <iostream>
#include<string.h>
using namespace std;
int main() {
const string ans[6]={"BCG","BGC","CBG","CGB","GBC","GCB"};
int num[9],cal[6];
memset(num,0,sizeof(num));
memset(cal,0,sizeof(cal));
while(cin>>num[0])
{
for(int c=1;c<9;c++)
cin>>num[c];
//only move need to calculate
cal[0]=num[3]+num[6]+num[2]+num[8]+num[1]+num[4];//bcg
cal[1]=num[3]+num[6]+num[1]+num[7]+num[2]+num[5];//bgc
cal[2]=num[5]+num[8]+num[0]+num[6]+num[1]+num[4];//cbg
cal[3]=num[5]+num[8]+num[1]+num[7]+num[0]+num[3];//cgb
cal[4]=num[4]+num[7]+num[0]+num[6]+num[2]+num[5];//gbc
cal[5]=num[4]+num[7]+num[2]+num[8]+num[0]+num[3];//gcb
int min=0, _ans=0,m =0;
min=cal[0];
for(;m<6;m++)
{
if(min>cal[m]){
min=cal[m];
_ans=m;
}
}
cout<<ans[_ans]<<" "<<min<<endl;
}
return 0;
}
留言
張貼留言