Advertisement
dyamondz

Quadrat llatí - P91748

Dec 27th, 2017
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. typedef vector<int> Fila;
  7. typedef vector<Fila> Quadrat;
  8.  
  9. bool es_llati(const Quadrat& q){
  10.     Quadrat aux=q;
  11.     int mida=q.size();
  12.     for(int i=0;i<mida;++i){
  13.         Fila fx(mida,0);
  14.         for(int j=0;j<mida;++j) fx[j]=q[i][j];
  15.         sort(fx.begin(),fx.end());
  16.         for(int j=0;j<mida;++j){
  17.             if(fx[j]!=j+1) return false;
  18.         }
  19.     }
  20.     for(int i=0;i<mida;++i){
  21.         Fila a(mida,0);
  22.         for(int j=0;j<mida;++j){
  23.             a[j]=aux[j][i];
  24.         }
  25.         sort(a.begin(),a.end());
  26.         for(int j=0;j<mida;++j){
  27.             if(a[j]!=j+1) return false;
  28.         }
  29.     }
  30.     return true;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement