Advertisement
Raul_julian

Quad_Magico-[OBI]

Jan 7th, 2014
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.66 KB | None | 0 0
  1. #include <string.h>
  2. #include <stdio.h>
  3.  
  4. int main() {
  5.    
  6.     int tam, i, j, contCol=0, contLin =0, contFLin = 0, contFCol = 0, contDa =0, contDb = 0;
  7.  
  8.     scanf("%d", &tam);
  9.    
  10.     int __vetNumbers[tam][tam];
  11.    
  12.         for(i=0; i<tam; i++) {
  13.             for(j=0; j<tam; j++) {
  14.                 scanf("%d", &__vetNumbers[i][j]);
  15.             }
  16.         }
  17.  
  18.         for(i=0; i<tam; i++) {
  19.                         for(j=0; j<tam; j++) {
  20.                                 contLin = contLin + __vetNumbers[i][j];
  21.                         }
  22.            
  23.             if(contFLin == 0) {
  24.             contFLin = contLin; }
  25.    
  26.             if(contFLin != contLin) {  
  27.                 printf("-1");
  28.                 return;
  29.             }
  30.    
  31.             contLin = 0;  
  32.            
  33.                 }
  34.  
  35.         for(i=0; i<tam; i++) {
  36.             for(j=0; j<tam; j++) {
  37.                 contCol = contCol + __vetNumbers[j][i];
  38.             }
  39.            
  40.             if(contFCol == 0) {
  41.             contFCol = contCol; }
  42.  
  43.             if(contFCol != contCol) {
  44.                
  45.                 printf("-1");
  46.                 return;
  47.             }
  48.            
  49.             contCol = 0;
  50.         }
  51.    
  52.         for(i=0; i<tam; i++) {
  53.             for(j=0; j<tam; j++) {
  54.                 if(i == j) {  
  55.                     contDa = contDa + __vetNumbers[i][j];
  56.                 }
  57.             }
  58.         }
  59.    
  60.             if(contDa != contFCol) {
  61.    
  62.                 printf("-1");
  63.                 return;
  64.             }
  65.        
  66.         for(i=tam-1; i>=0; i--) {
  67.                         for(j=tam-1; j>=0; j--) {
  68.                                 if(i == j) {
  69.                                         contDb = contDb + __vetNumbers[i][j];
  70.                                 }
  71.                         }
  72.                 }
  73.  
  74.                         if(contDb != contFCol) {
  75.  
  76.                                 printf("-1");
  77.                                 return;
  78.                         }
  79.            
  80.    
  81.         printf("%d\n", contFCol);  
  82.            
  83.  
  84.  
  85.         return 0;  
  86.  
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement