행렬 회전 팁

jahlee·2023년 9월 23일
0

개인 공부

목록 보기
23/23
#include <iostream>
#include <vector>
#define SIZE 3
using namespace std;

int main() {
	vector<string> temp = {"123", "8 4", "765"};
	vector<string> res(SIZE, "   ");
	// 시계
	for (int i = 0; i < SIZE; i++) {
		for (int j = 0; j < SIZE; j++) {
			res[j][SIZE-i-1] = temp[i][j];
		}
	}
	for (auto c : res) {
		cout << c << "\n";
	}
	cout << "=====\n";
	// 반시계
	for (int i = 0; i < SIZE; i++) {
		for (int j = 0; j < SIZE; j++) {
			res[SIZE-j-1][i] = temp[i][j];
		}
	}
	for (auto c : res) {
		cout << c << "\n";
	}


}

0개의 댓글