티스토리 뷰

https://www.acmicpc.net/problem/5373

 

5373번: 큐빙

각 테스트 케이스에 대해서 큐브를 모두 돌린 후의 윗 면의 색상을 출력한다. 첫 번째 줄에는 뒷 면과 접하는 칸의 색을 출력하고, 두 번째, 세 번째 줄은 순서대로 출력하면 된다. 흰색은 w, 노란

www.acmicpc.net

const fs = require("fs");
const input = fs
  .readFileSync("./dev/stdin")
  .toString()
  .trim()
  .split("\n").map(v=>v.trim())


 



  let test = [
    [ [ 0, 1, 2 ], [ 3, 4, 5 ], [ 6, 7, 8 ] ],
    [ [ 9, 10, 11 ], [ 12, 13, 14 ], [ 15, 16, 17 ] ],
    [ [ 18, 19, 20 ], [ 21, 22, 23 ], [ 24, 25, 26 ] ]
  ]

  const answer = [];
  let color = [];
  let origin = [
    {b:'o',u:'w',l:'g'}, //0
    {b:'o',u:'w'},       //1
    {b:'o',u:'w',r:'b'}, //2
    {u:'w',l:'g'},       //3
    {u:'w'},              //4
    {u:'w',r:'b'},       //5
    {f:'r',u:'w',l:'g'},  //6
    {f:'r',u:'w'},        //7
    {f:'r',u:'w',r:'b'},   //8
    

    {b:'o',l:'g'},         //9
    {b:'o',},              //10
    {b:'o',r:'b'},           //11
    {l:'g'},                 //12
    {},                      //13 
    {r:'b'},                  //14
    {f:'r',l:'g'},            //15
    {f:'r',},                 //16
    {f:'r',r:'b'},             //17

    {b:'o',d:'y',l:'g'},   //18
    {b:'o',d:'y'},         //19
    {b:'o',d:'y',r:'b'},   //20
    {d:'y',l:'g'},         //21
    {d:'y'},                //22
    {d:'y',r:'b'},          //23
    {f:'r',d:'y',l:'g'},    //24
    {f:'r',d:'y'},          //25
    {f:'r',d:'y',r:'b'},    //26
  ]

  //minus 반시계 
  // plus 시계
  function U_minus(){
    const store = color[0];
    color[0] = {b:color[2].r,u:color[2].u,l:color[2].b}
    color[2] = {b:color[8].r,u:color[8].u,r:color[8].f}
    color[8] = {f:color[6].l,u:color[6].u,r:color[6].f}
    color[6] = {f:store.l,   u:store.u,   l:store.b}

    const store2 = color[1];
    color[1] = {u:color[5].u, b:color[5].r}
    color[5] = {u:color[7].u, r:color[7].f}
    color[7] = {u:color[3].u, f:color[3].l}
    color[3] = {u:store2.u,   l:store2.b}
  }

  function U_plus(){
    const store = color[0];
    color[0] = {b:color[6].l, u:color[6].u, l:color[6].f}
    color[6] = {f:color[8].r, u:color[8].u, l:color[8].f}
    color[8] = {f:color[2].r, u:color[2].u, r:color[2].b}
    color[2] = {b:store.l,    u:store.u,    r:store.b}

    const store2 = color[1];
    color[1] = {u:color[3].u, b:color[3].l}
    color[3] = {u:color[7].u, l:color[7].f}
    color[7] = {u:color[5].u, f:color[5].r}
    color[5] = {u:store2.u,   r:store2.b}
  }


  function D_plus(){
    const store = color[18];
    color[18] = {b:color[20].r,d:color[20].d,l:color[20].b}
    color[20] = {b:color[26].r,d:color[26].d,r:color[26].f}
    color[26] = {f:color[24].l,d:color[24].d,r:color[24].f}
    color[24] = {f:store.l,   d:store.d,   l:store.b}

    const store2 = color[19];
    color[19] = {d:color[23].d, b:color[23].r}
    color[23] = {d:color[25].d, r:color[25].f}
    color[25] = {d:color[21].d, f:color[21].l}
    color[21] = {d:store2.d,   l:store2.b}
  }

  function D_minus(){
    const store = color[18];
    color[18] = {b:color[24].l, d:color[24].d, l:color[24].f}
    color[24] = {f:color[26].r, d:color[26].d, l:color[26].f}
    color[26] = {f:color[20].r, d:color[20].d, r:color[20].b}
    color[20] = {b:store.l,    d:store.d,    r:store.b}

    const store2 = color[19];
    color[19] = {d:color[21].d, b:color[21].l}
    color[21] = {d:color[25].d, l:color[25].f}
    color[25] = {d:color[23].d, f:color[23].r}
    color[23] = {d:store2.d,   r:store2.b}
  }







  function F_minus(){
    const store1 = color[6];
    color[6] = {f:color[8].f, u:color[8].r, l:color[8].u}
    color[8] = {f:color[26].f, u:color[26].r, r:color[26].d}
    color[26] = {f:color[24].f, d:color[24].l, r:color[24].d}
    color[24] = {f:store1.f, d:store1.l, l:store1.u}
    
    const store2 = color[7];
    color[7] = {f:color[17].f, u:color[17].r};
    color[17] = {f:color[25].f, r:color[25].d}
    color[25] = {f:color[15].f, d:color[15].l}
    color[15] = {f:store2.f, l:store2.u}
  }

  function F_plus(){
    const store1 = color[6];
    color[6] = {f:color[24].f, u:color[24].l, l:color[24].d}
    color[24] = {f:color[26].f, d:color[26].r, l:color[26].d}
    color[26] = {f:color[8].f, d:color[8].r, r:color[8].u}
    color[8] = {f:store1.f, u:store1.l, r:store1.u}
    
    const store2 = color[7];
    color[7] = {f:color[15].f, u:color[15].l};
    color[15] = {f:color[25].f, l:color[25].d}
    color[25] = {f:color[17].f, d:color[17].r}
    color[17] = {f:store2.f, r:store2.u}
  }

  function B_plus(){
    const store1 = color[0];
    color[0] = {b:color[2].b, u:color[2].r, l:color[2].u}
    color[2] = {b:color[20].b, u:color[20].r, r:color[20].d}
    color[20] = {b:color[18].b, d:color[18].l, r:color[18].d}
    color[18] = {b:store1.b, d:store1.l, l:store1.u}
    
    const store2 = color[1];
    color[1] = {b:color[11].b, u:color[11].r};
    color[11] = {b:color[19].b, r:color[19].d}
    color[19] = {b:color[9].b, d:color[9].l}
    color[9] = {b:store2.b, l:store2.u}
  }

  function B_minus(){
    const store1 = color[0];
    color[0] = {b:color[18].b, u:color[18].l, l:color[18].d}
    color[18] = {b:color[20].b, d:color[20].r, l:color[20].d}
    color[20] = {b:color[2].b, d:color[2].r, r:color[2].u}
    color[2] = {b:store1.b, u:store1.l, r:store1.u}
    
    const store2 = color[1];
    color[1] = {b:color[9].b, u:color[9].l};
    color[9] = {b:color[19].b, l:color[19].d}
    color[19] = {b:color[11].b, d:color[11].r}
    color[11] = {b:store2.b, r:store2.u}
  }





  function L_minus(){
    const store1 = color[0];
    color[0] = {b:color[6].u,   u:color[6].f,   l:color[6].l};
    color[6] = {f:color[24].d,  u:color[24].f , l:color[24].l};
    color[24] = {f:color[18].d, d:color[18].b,  l:color[18].l}
    color[18] = {b:store1.u,    d:store1.b,     l:store1.l}
    
    const store2 = color[3];
    color[3] =  {u:color[15].f,  l:color[15].l};
    color[15] = {f:color[21].d, l:color[21].l}
    color[21] = {d:color[9].b,  l:color[9].l}
    color[9]  = {b:store2.u,    l:store2.l}
  }
  
  function L_plus(){
    const store1 = color[0];
    color[0] = { u:color[18].b, b:color[18].d,  l:color[18].l};
    color[18] = {d:color[24].f, b:color[24].d,  l:color[24].l};
    color[24] = {d:color[6].f,  f:color[6].u,   l:color[6].l}
    color[6] = { u:store1.b,    f:store1.u,     l:store1.l}

    const store2 = color[3];
    color[3] = {  u:color[9].b,  l:color[9].l};
    color[9] = {  b:color[21].d, l:color[21].l}
    color[21] = { d:color[15].f, l:color[15].l}
    color[15] = { f:store2.u,    l:store2.l}
    
  }
  ////////////////////////////////////////////////////////// 여기까지
  function R_plus(){
    const store1 = color[2];
    color[2] = {b:color[8].u,   u:color[8].f,   r:color[8].r};
    color[8] = {f:color[26].d,  u:color[26].f , r:color[26].r};
    color[26] = {f:color[20].d, d:color[20].b,  r:color[20].r}
    color[20] = {b:store1.u,    d:store1.b,     r:store1.r}
    
    const store2 = color[5];
    color[5] =  {u:color[17].f,  r:color[17].r};
    color[17] = {f:color[23].d, r:color[23].r}
    color[23] = {d:color[11].b,  r:color[11].r}
    color[11]  = {b:store2.u,    r:store2.r}
  }
  
  function R_minus(){
    const store1 = color[2];
    color[2] = { u:color[20].b, b:color[20].d,  r:color[20].r};
    color[20] = {d:color[26].f, b:color[26].d,  r:color[26].r};
    color[26] = {d:color[8].f,  f:color[8].u,   r:color[8].r}
    color[8] = { u:store1.b,    f:store1.u,     r:store1.r}

    const store2 = color[5];
    color[5] = {  u:color[11].b,  r:color[11].r};
    color[11] = {  b:color[23].d, r:color[23].r}
    color[23] = { d:color[17].f, r:color[17].r}
    color[17] = { f:store2.u,    r:store2.r}
    
  }








  const T = +input.shift()

  for(let i = 0; i<T; i++){
    color = origin.map(v=>{return{...v}})
    const N = +input.shift();    
      const rotate = input.shift().split(' ');
      rotate.forEach(v=>{
        switch(v){
          case 'U+':
             U_plus();
            break;
          case 'U-':
            U_minus(); 
            break;
          case 'D+':
            D_plus()
            break;
          case 'D-':
            D_minus();
            break;
          case 'F+':
            F_plus();
            break;
          case 'F-':
            F_minus()
            break;
          case 'B+':
            B_plus()
            break;
          case 'B-':
            B_minus()
            break;
          case 'L-':
            L_minus();
            break;
          case 'L+':
            L_plus();
            break;
          case 'R+':
            R_plus();
            break;
          case 'R-':
            R_minus();
            break;
        }
      })

      answer.push(color[0].u+color[1].u+color[2].u)
      answer.push(color[3].u+color[4].u+color[5].u)
      answer.push(color[6].u+color[7].u+color[8].u)
  }
  


console.log(answer.join('\n'))
728x90
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
글 보관함