#include #include #include #include void bubsort(int arr[], int size) { int e; for (int i = 0; i < size; i++) { for (int j = 1; j < size; j++) { if (arr[j - 1] > arr [j]) { e = arr[j - 1]; arr[j - 1] = arr[j]; arr[j] = e; } } } } int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int r1 = 0,r2 = 0,r3 = 0; int c1 = 0,c2 = 0,c3 = 0; int d1 = 0, d2 = 0,total = 0; int a1,a2,b1,b2,c = 5; int matrix[3][3]; for (int i = 0;i < 3;i++) { for (int j = 0;j < 3;j++) { scanf("%i",&matrix[i][j]); } scanf("\n"); //printf("\n"); } int mat1[3][3] = {2,9,4, 7,5,3, 6,1,8}; int mat2[3][3] = {6,1,8, 7,5,3, 2,9,4}; int mat3[3][3] = {4,9,2, 3,5,7, 8,1,6}; int mat4[3][3] = {8,1,6, 3,5,7, 4,9,2}; int mat5[3][3] = {8,3,4, 1,5,9, 6,7,2}; int mat6[3][3] = {4,3,8, 9,5,1, 2,7,6}; int mat7[3][3] = {6,7,2, 1,5,9, 8,3,4}; int mat8[3][3] = {2,7,6, 9,5,1, 4,3,8}; int cost[8] = {0}; for (int i = 0;i < 3;i++) { for (int j = 0;j < 3;j++) { if (matrix[i][j] != mat1[i][j]){ cost[0] += abs(matrix[i][j] - mat1[i][j]); }//printf("%i ",cMat[i][j]); if (matrix[i][j] != mat2[i][j]){ cost[1] += abs(matrix[i][j] - mat2[i][j]); }//printf("%i ",cMat[i][j]); if (matrix[i][j] != mat3[i][j]){ cost[2] += abs(matrix[i][j] - mat3[i][j]); }//printf("%i ",cMat[i][j]); if (matrix[i][j] != mat4[i][j]){ cost[3] += abs(matrix[i][j] - mat4[i][j]); }//printf("%i ",cMat[i][j]); if (matrix[i][j] != mat5[i][j]){ cost[4] += abs(matrix[i][j] - mat5[i][j]); }//printf("%i ",cMat[i][j]); if (matrix[i][j] != mat6[i][j]){ cost[5] += abs(matrix[i][j] - mat6[i][j]); }//printf("%i ",cMat[i][j]); if (matrix[i][j] != mat7[i][j]){ cost[6] += abs(matrix[i][j] - mat7[i][j]); }//printf("%i ",cMat[i][j]); if (matrix[i][j] != mat8[i][j]){ cost[7] += abs(matrix[i][j] - mat8[i][j]); }//printf("%i ",cMat[i][j]); } //printf("\n"); } //printf("%i %i %i %i %i %i %i %i\n",cost1,cost2,cost3,cost4,cost5,cost6,cost7,cost8); int min = 0; /*if ((cost1 <= cost2) && (cost1 <= cost3) &&(cost1 <= cost4) &&(cost1 <= cost5) &&(cost1 <= cost6) &&(cost1 <= cost7) &&(cost1 <= cost8)) { min = cost1; } if ((cost2 <= cost1) && (cost2 <= cost3) &&(cost2 <= cost4) &&(cost2 <= cost5) &&(cost2 <= cost6) &&(cost2 <= cost7) &&(cost2 <= cost8)) { min = cost2; } if ((cost3 <= cost2) && (cost3 <= cost1) &&(cost3 <= cost4) &&(cost3 <= cost5) &&(cost3 <= cost6) &&(cost3 <= cost7) &&(cost3 <= cost8)) { min = cost3; } if ((cost4 <= cost2) && (cost4 <= cost3) &&(cost4 <= cost1) &&(cost4 <= cost5) &&(cost4 <= cost6) &&(cost4 <= cost7) &&(cost4 <= cost8)) { min = cost4; } if ((cost5 <= cost2) && (cost5 <= cost3) &&(cost5 <= cost4) &&(cost5 <= cost1) &&(cost5 <= cost6) &&(cost5 <= cost7) &&(cost5 <= cost8)) { min = cost5; } if ((cost6 <= cost2) && (cost6 <= cost3) &&(cost6 <= cost4) &&(cost6 <= cost5) &&(cost6 <= cost1) &&(cost6 <= cost7) &&(cost6 <= cost8)) { min = cost6; } if ((cost7 <= cost2) && (cost7 <= cost3) &&(cost7 <= cost4) &&(cost7 <= cost5) &&(cost7 <= cost6) &&(cost7 <= cost1) &&(cost7 <= cost8)) { min = cost7; } if ((cost8 <= cost2) && (cost8 <= cost3) &&(cost8 <= cost4) &&(cost8 <= cost5) &&(cost8 <= cost6) &&(cost8 <= cost7) &&(cost8 <= cost1)) { min = cost8; }*/ //printf() bubsort(cost,8); printf("%i",cost[0]); return 0; }