█████████ ████ ███░░░░░███ ░░███ ███ ░░░ ██████ ███████ ██████ ██████ ░███ ███░░███ ███░░███ ███░░███ ███░░███ ░███ ░███ ░███░███ ░███ ░███████ ░███ ░███ ░░███ ███░███ ░███░███ ░███ ░███░░░ ░███ ░███ ░░█████████ ░░██████ ░░████████░░██████ ░░██████ ░░░░░░░░░ ░░░░░░ ░░░░░░░░ ░░░░░░ ░░░░░░

Envío 6402

Problema 0xe1 - Cuadrado mágico

  • Autor: Camilo15
  • Fecha: 2022-07-04 18:41:08 UTC (Hace más de 2 años)
Caso # Resultado Tiempo Memoria
#1
Error de compilación
                      main.cpp:20:29: error: use of undeclared identifier 'j'
    firstDiagonal += arr[i][j];
                            ^
1 error generated.

                    
#2
Error de compilación
                      main.cpp:20:29: error: use of undeclared identifier 'j'
    firstDiagonal += arr[i][j];
                            ^
1 error generated.

                    
#3
Error de compilación
                      main.cpp:20:29: error: use of undeclared identifier 'j'
    firstDiagonal += arr[i][j];
                            ^
1 error generated.

                    
#4
Error de compilación
                      main.cpp:20:29: error: use of undeclared identifier 'j'
    firstDiagonal += arr[i][j];
                            ^
1 error generated.

                    
#5
Error de compilación
                      main.cpp:20:29: error: use of undeclared identifier 'j'
    firstDiagonal += arr[i][j];
                            ^
1 error generated.

                    
#6
Error de compilación
                      main.cpp:20:29: error: use of undeclared identifier 'j'
    firstDiagonal += arr[i][j];
                            ^
1 error generated.

                    
#7
Error de compilación
                      main.cpp:20:29: error: use of undeclared identifier 'j'
    firstDiagonal += arr[i][j];
                            ^
1 error generated.

                    
#8
Error de compilación
                      main.cpp:20:29: error: use of undeclared identifier 'j'
    firstDiagonal += arr[i][j];
                            ^
1 error generated.

                    
#9
Error de compilación
                      main.cpp:20:29: error: use of undeclared identifier 'j'
    firstDiagonal += arr[i][j];
                            ^
1 error generated.

                    
#10
Error de compilación
                      main.cpp:20:29: error: use of undeclared identifier 'j'
    firstDiagonal += arr[i][j];
                            ^
1 error generated.

                    
#11
Error de compilación
                      main.cpp:20:29: error: use of undeclared identifier 'j'
    firstDiagonal += arr[i][j];
                            ^
1 error generated.

                    
#12
Error de compilación
                      main.cpp:20:29: error: use of undeclared identifier 'j'
    firstDiagonal += arr[i][j];
                            ^
1 error generated.

                    
#13
Error de compilación
                      main.cpp:20:29: error: use of undeclared identifier 'j'
    firstDiagonal += arr[i][j];
                            ^
1 error generated.

                    
#14
Error de compilación
                      main.cpp:20:29: error: use of undeclared identifier 'j'
    firstDiagonal += arr[i][j];
                            ^
1 error generated.

                    
#15
Error de compilación
                      main.cpp:20:29: error: use of undeclared identifier 'j'
    firstDiagonal += arr[i][j];
                            ^
1 error generated.

                    
#16
Error de compilación
                      main.cpp:20:29: error: use of undeclared identifier 'j'
    firstDiagonal += arr[i][j];
                            ^
1 error generated.

                    
#17
Error de compilación
                      main.cpp:20:29: error: use of undeclared identifier 'j'
    firstDiagonal += arr[i][j];
                            ^
1 error generated.

                    
#18
Error de compilación
                      main.cpp:20:29: error: use of undeclared identifier 'j'
    firstDiagonal += arr[i][j];
                            ^
1 error generated.

                    
#19
Error de compilación
                      main.cpp:20:29: error: use of undeclared identifier 'j'
    firstDiagonal += arr[i][j];
                            ^
1 error generated.

                    
#20
Error de compilación
                      main.cpp:20:29: error: use of undeclared identifier 'j'
    firstDiagonal += arr[i][j];
                            ^
1 error generated.

                    
Puntos totales: 0 / 100

Código

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n; cin>>n;
  int arr[n][n];
  int firstDiagonal = 0;
  int secondDiagonal = 0;
  int sum;
  int x = n-1, y = 0;
  bool isMagic = true;
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < n; j++) {
      cin>>arr[i][j];
    }
  }
  for(int i = 0; i < n; i++) {
    int rowSum = 0;
    int colSum = 0;
    firstDiagonal += arr[i][j];
    secondDiagonal += arr[x][y];
    for(int j = 0; j < n; j++) {
      rowSum += arr[i][j];
      colSum += arr[j][i];
    }
    if(i > 0) {
      if(!(rowSum == colSum && colSum == sum)) {
        isMagic = false;
        break;
      }
    } else {
      if(rowSum == colSum) sum = rowSum;
      else {
        isMagic = false;
        break;
      }
    }
    x--; y++;
  }
  if(isMagic) {
    isMagic = firstDiagonal == secondDiagonal && secondDiagonal == sum;
  }
  if(isMagic) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}