#include #include #include #include #include using namespace std; bool isMagic(vector > matrix) { if(!((matrix[0][0] + matrix[0][1] +matrix[0][2]) == 15)) return false; if(!((matrix[1][0] + matrix[1][1] +matrix[1][2]) == 15)) return false; if(!((matrix[2][0] + matrix[2][2] +matrix[2][2]) == 15)) return false; if(!((matrix[0][0] + matrix[1][0] +matrix[2][0]) == 15)) return false; if(!((matrix[1][0] + matrix[1][1] +matrix[1][2]) == 15)) return false; if(!((matrix[2][2] + matrix[2][1] +matrix[2][2]) == 15)) return false; if(!((matrix[0][0] + matrix[1][1] +matrix[2][2]) == 15)) return false; if(!((matrix[0][2] + matrix[1][1] +matrix[2][0]) == 15)) return false; cout<< " reached the end"<> M1 , vector > M2){ int diff = 0; for(int i = 0 ; i < 3 ; i++) for(int j = 0 ; j < 3 ; j++) diff += abs(M1[i][j] - M2[i][j]); return diff; } int main() { vector >> allSquares{{{4,9,2},{3,5,7},{8,1,6}},{{4,3,8},{9,5,1},{2,7,6}},{{8,1,6},{3,5,7},{4,9,2}},{{8,3,4},{1,5,9},{6,7,2}},{{2,9,4},{7,5,3},{6,1,8}},{{2,7,6},{9,5,1},{4,3,8}},{{6,7,2},{1,5,9},{8,3,4}},{{6,1,8},{7,5,3},{2,9,4}}}; int minDiff = 1000; /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int sum = 0; vector > matrix; for(int i = 0 ; i < 3 ; i++){ vector in; for(int j = 0; j <3 ; j++){ int n; cin >> n ; in.push_back(n); } matrix.push_back(in); } for(int i = 0 ; i < 8 ; i++)/*{ for(int r = 0 ; r < 3 ; r++){ for(int c = 0 ; c < 3 ; c++) cout<< allSquares[i][r][c] << " "; cout << endl; } cout << endl; }*/ minDiff > findSquareDiff(matrix,allSquares[i]) ? minDiff = findSquareDiff(matrix,allSquares[i]) : false; cout << minDiff; return 0; }