#include #include #include #include #include using namespace std; int cost=99999; void calc(int a[3][3],int b[3][3]){ int i,j,temp=0; for(i=0;i<3;i++){ for(j=0;j<3;j++){ temp+=abs(a[i][j]-b[i][j]); } } if(cost>temp){ cost=temp; } } int main() { int inp[3][3],i,j; for(i=0;i<3;i++){ for(j=0;j<3;j++){ cin>>inp[i][j]; } } int a[3][3]={8,1,6,3,5,7,4,9,2}; int b[3][3]={6,1,8,7,5,3,2,9,4}; int c[3][3]={8,3,4,1,5,9,6,7,2}; int d[3][3]={6,7,2,1,5,9,8,3,4}; int e[3][3]={4,9,2,3,5,7,8,1,6}; int f[3][3]={2,9,4,7,5,3,6,1,8}; int g[3][3]={4,3,8,9,5,1,2,7,6}; int h[3][3]={2,7,6,9,5,1,4,3,8}; calc(inp,a); calc(inp,b); calc(inp,c); calc(inp,d); calc(inp,e); calc(inp,f); calc(inp,g); calc(inp,h); cout<