Ankit_132

C

Nov 4th, 2023
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1.  
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     vector<vector<int>> a(9, vector<int> (9));
  9.     for(int i=0; i<9; i++)  for(int j=0; j<9; j++)    cin>>a[i][j];
  10.  
  11.     int f = 1;
  12.  
  13.     set<int> st;
  14.  
  15.     for(int i=0; i<9; i++)
  16.     {
  17.         st.clear();
  18.         for(int j=0; j<9; j++)
  19.             st.insert(a[i][j]);
  20.  
  21.         f &= (st.size() == 9);
  22.  
  23.         st.clear();
  24.         for(int j=0; j<9; j++)
  25.             st.insert(a[j][i]);
  26.  
  27.         f &= (st.size() == 9);
  28.     }
  29.  
  30.     for(int i=0; i<9; i+=3)
  31.     {
  32.         for(int j=0; j<9; j+=3)
  33.         {
  34.             st.clear();
  35.             st.insert(a[i][j]);
  36.             st.insert(a[i][j+1]);
  37.             st.insert(a[i][j+2]);
  38.             st.insert(a[i+1][j]);
  39.             st.insert(a[i+1][j+1]);
  40.             st.insert(a[i+1][j+2]);
  41.             st.insert(a[i+2][j]);
  42.             st.insert(a[i+2][j+1]);
  43.             st.insert(a[i+2][j+2]);
  44.             f &= (st.size() == 9);
  45.         }
  46.     }
  47.  
  48.     if(f)       cout<<"Yes\n";
  49.     else        cout<<"No\n";
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment