-
[Algorithm Team Note] rotate (배열 회전하기)Algorithm Team Note 2021. 3. 14. 20:43
배열을 회전하는 경우가 많다
NXM 크기의 배열을 시계방향으로 90도 회전하는 경우
회전된 (x,y) 좌표는 회전되기 이전 (N-1-y, x) 좌표에서 온 것이다
vector<vector<char>> rotate(vector<vector<char>> b) { int bx = b.size(); int by = b[0].size(); vector<vector<char>> tmpb; for (int i = 0;i < by;i++) { vector<char> tmpv; for (int j = 0;j < bx;j++) { tmpv.push_back(b[bx-1-j][i]); } tmpb.push_back(tmpv); } return tmpb; }
'Algorithm Team Note' 카테고리의 다른 글
[Algorithm Team Note] tilt (배열 기울이기) (0) 2021.03.14