Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.53 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define ll long long
  6. #define mp make_pair
  7. #define f first
  8. #define s second
  9. #define pb push_back
  10.  
  11. ifstream fin("rubikscube.txt");
  12.  
  13. class RubiksCube
  14. {
  15. private:
  16.     vector <vector <int> > cube[6];
  17.  
  18. public:
  19.     ///Cube Constructor
  20.     //In: Vector containing cube values from 1st to 6th face
  21.     RubiksCube(vector <int> v)
  22.     {
  23.         int line = 0;
  24.         int curr_face = 0;
  25.         vector <int> curr_row;
  26.         for(auto it:v)
  27.         {
  28.             if(curr_face==0 || curr_face==5)
  29.             {
  30.                 curr_row.pb(it);
  31.                 if(curr_row.size()==3)
  32.                 {
  33.                     cube[curr_face].pb(curr_row);
  34.                     curr_row.clear();
  35.                     if(cube[curr_face].size()==3)
  36.                         curr_face++;
  37.                 }
  38.             }
  39.             else
  40.             {
  41.                 curr_row.pb(it);
  42.                 if(curr_row.size()==3)
  43.                 {
  44.                     cube[curr_face].pb(curr_row);
  45.                     curr_row.clear();
  46.                     curr_face++;
  47.                 }
  48.                 if(curr_face==5 && line<2)
  49.                     ++line,curr_face=1;
  50.             }
  51.         }
  52.     }
  53.  
  54.     ///Query dominant color on given face
  55.     //In: Face number
  56.     //Out: Dominant color
  57.     int find_dominant_color(int face)
  58.     {
  59.         face--; // faces are numbered from 0 to 5 in the internal model
  60.         int d[7];
  61.         memset(d, 0, sizeof(d));
  62.         for(auto it:cube[face])
  63.         {
  64.             for(auto x:it)
  65.                 ++d[x];
  66.         }
  67.         int mx = 0;
  68.         int ans = 0;
  69.         for(int i=1; i<7; ++i)
  70.             if(d[i]>mx)
  71.                 mx=d[i],ans=i;
  72.         return ans;
  73.     }
  74.  
  75.     ///Print cube as a plus
  76.     void print_cube_plus()
  77.     {
  78.         //print 1st face
  79.         for(auto it:cube[0])
  80.         {
  81.             for(int j=1; j<=3; ++j)
  82.                 cout<<"  ";
  83.             for(auto x:it)
  84.                 cout<<x<<' ';
  85.             cout<<'\n';
  86.         }
  87.  
  88.         //print faces 2-5
  89.         for(int i=0; i<3; ++i)
  90.         {
  91.             for(int k=1; k<5; ++k)
  92.                 for(int j=0; j<3; ++j)
  93.                     cout<<cube[k][i][j]<<' ';
  94.             cout<<'\n';
  95.         }
  96.  
  97.         //print 6th face
  98.         for(auto it:cube[5])
  99.         {
  100.             for(int j=1; j<=3; ++j)
  101.                 cout<<"  ";
  102.             for(auto x:it)
  103.                 cout<<x<<' ';
  104.             cout<<'\n';
  105.         }
  106.  
  107.     }
  108.  
  109.     ///Check if given face is solved
  110.     //In: Face number
  111.     //Out: 0/1
  112.     bool check_solved_face(int face)
  113.     {
  114.         face--;
  115.         int d[7];
  116.         memset(d, 0, sizeof(d));
  117.         for(auto it:cube[face])
  118.         {
  119.             for(auto x:it)
  120.                 ++d[x];
  121.         }
  122.         for(int i=1; i<7; ++i)
  123.             if(d[i]==6)
  124.                 return 1;
  125.         return 0;
  126.     }
  127.  
  128.     ///Check if given face has an X
  129.     //In: Face number
  130.     //Out: 0/1
  131.     bool check_x(int face)
  132.     {
  133.         face--;
  134.         if(cube[face][0][0] == cube[face][0][2] &&
  135.            cube[face][0][2] == cube[face][1][1] &&
  136.            cube[face][1][1] == cube[face][2][0] &&
  137.            cube[face][2][0] == cube[face][2][2] &&
  138.            cube[face][2][2] != cube[face][0][1] &&
  139.            cube[face][0][1] == cube[face][1][0] &&
  140.            cube[face][1][0] == cube[face][1][2] &&
  141.            cube[face][1][2] == cube[face][2][1])
  142.             return 1;
  143.         return 0;
  144.     }
  145.  
  146.     ///Check if given face has an X
  147.     //In: Face number
  148.     //Out: 0/1
  149.     bool check_o(int face)
  150.     {
  151.         face--;
  152.         if(cube[face][0][0] == cube[face][0][2] &&
  153.            cube[face][0][2] == cube[face][2][0] &&
  154.            cube[face][2][0] == cube[face][2][2] &&
  155.            cube[face][2][2] != cube[face][0][1] &&
  156.            cube[face][0][1] == cube[face][1][0] &&
  157.            cube[face][1][0] == cube[face][1][1] &&
  158.            cube[face][1][1] == cube[face][1][2] &&
  159.            cube[face][1][2] == cube[face][2][1])
  160.             return 1;
  161.         return 0;
  162.     }
  163.  
  164.     ///Shuffles cube
  165.     void shuffle_cube()
  166.     {
  167.         ///???
  168.     }
  169.  
  170. };
  171.  
  172. int main()
  173. {
  174.     cin.sync_with_stdio(false);
  175.     cout.sync_with_stdio(false);
  176.  
  177.     vector <int> in;
  178.     char x;
  179.     ///assume input is correct and completes the cube
  180.     while(fin>>x)
  181.     {
  182.         if(x<='9' && x>='0')
  183.         {
  184.             in.pb(x-'0');
  185.         }
  186.     }
  187.  
  188.     RubiksCube cube(in);
  189.  
  190.     cube.print_cube_plus();
  191.  
  192.     cout<<cube.find_dominant_color(6);
  193. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement