Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define mp make_pair
- #define f first
- #define s second
- #define pb push_back
- ifstream fin("rubikscube.txt");
- class RubiksCube
- {
- private:
- vector <vector <int> > cube[6];
- public:
- ///Cube Constructor
- //In: Vector containing cube values from 1st to 6th face
- RubiksCube(vector <int> v)
- {
- int line = 0;
- int curr_face = 0;
- vector <int> curr_row;
- for(auto it:v)
- {
- if(curr_face==0 || curr_face==5)
- {
- curr_row.pb(it);
- if(curr_row.size()==3)
- {
- cube[curr_face].pb(curr_row);
- curr_row.clear();
- if(cube[curr_face].size()==3)
- curr_face++;
- }
- }
- else
- {
- curr_row.pb(it);
- if(curr_row.size()==3)
- {
- cube[curr_face].pb(curr_row);
- curr_row.clear();
- curr_face++;
- }
- if(curr_face==5 && line<2)
- ++line,curr_face=1;
- }
- }
- }
- ///Query dominant color on given face
- //In: Face number
- //Out: Dominant color
- int find_dominant_color(int face)
- {
- face--; // faces are numbered from 0 to 5 in the internal model
- int d[7];
- memset(d, 0, sizeof(d));
- for(auto it:cube[face])
- {
- for(auto x:it)
- ++d[x];
- }
- int mx = 0;
- int ans = 0;
- for(int i=1; i<7; ++i)
- if(d[i]>mx)
- mx=d[i],ans=i;
- return ans;
- }
- ///Print cube as a plus
- void print_cube_plus()
- {
- //print 1st face
- for(auto it:cube[0])
- {
- for(int j=1; j<=3; ++j)
- cout<<" ";
- for(auto x:it)
- cout<<x<<' ';
- cout<<'\n';
- }
- //print faces 2-5
- for(int i=0; i<3; ++i)
- {
- for(int k=1; k<5; ++k)
- for(int j=0; j<3; ++j)
- cout<<cube[k][i][j]<<' ';
- cout<<'\n';
- }
- //print 6th face
- for(auto it:cube[5])
- {
- for(int j=1; j<=3; ++j)
- cout<<" ";
- for(auto x:it)
- cout<<x<<' ';
- cout<<'\n';
- }
- }
- ///Check if given face is solved
- //In: Face number
- //Out: 0/1
- bool check_solved_face(int face)
- {
- face--;
- int d[7];
- memset(d, 0, sizeof(d));
- for(auto it:cube[face])
- {
- for(auto x:it)
- ++d[x];
- }
- for(int i=1; i<7; ++i)
- if(d[i]==6)
- return 1;
- return 0;
- }
- ///Check if given face has an X
- //In: Face number
- //Out: 0/1
- bool check_x(int face)
- {
- face--;
- if(cube[face][0][0] == cube[face][0][2] &&
- cube[face][0][2] == cube[face][1][1] &&
- cube[face][1][1] == cube[face][2][0] &&
- cube[face][2][0] == cube[face][2][2] &&
- cube[face][2][2] != cube[face][0][1] &&
- cube[face][0][1] == cube[face][1][0] &&
- cube[face][1][0] == cube[face][1][2] &&
- cube[face][1][2] == cube[face][2][1])
- return 1;
- return 0;
- }
- ///Check if given face has an X
- //In: Face number
- //Out: 0/1
- bool check_o(int face)
- {
- face--;
- if(cube[face][0][0] == cube[face][0][2] &&
- cube[face][0][2] == cube[face][2][0] &&
- cube[face][2][0] == cube[face][2][2] &&
- cube[face][2][2] != cube[face][0][1] &&
- cube[face][0][1] == cube[face][1][0] &&
- cube[face][1][0] == cube[face][1][1] &&
- cube[face][1][1] == cube[face][1][2] &&
- cube[face][1][2] == cube[face][2][1])
- return 1;
- return 0;
- }
- ///Shuffles cube
- void shuffle_cube()
- {
- ///???
- }
- };
- int main()
- {
- cin.sync_with_stdio(false);
- cout.sync_with_stdio(false);
- vector <int> in;
- char x;
- ///assume input is correct and completes the cube
- while(fin>>x)
- {
- if(x<='9' && x>='0')
- {
- in.pb(x-'0');
- }
- }
- RubiksCube cube(in);
- cube.print_cube_plus();
- cout<<cube.find_dominant_color(6);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement