Muscardinus
톱니바퀴 본문
728x90
https://www.acmicpc.net/problem/14891
#include <iostream>
#include <cstring>
using namespace std;
int n;
string gear[4];
int main() {
ios_base::sync_with_stdio(false);
for (int i = 0; i < 4; ++i) {
cin >> gear[i]; //입력 값 String
}
cin >> n;
int target, cmd;
for (int i = 0; i < n; i++) {
cin >> target >> cmd;
target--;
int move_cmd[4] = { 0, };
move_cmd[target] = cmd;
for (int left = target - 1; left >= 0; left--) { //기준점 왼쪽 확인
int right = left + 1;
if (gear[left][2] == gear[right][6]) break;
else move_cmd[left] = move_cmd[right] * -1;
}
for (int right = target + 1; right <= 3; right++) { //기준점 오른쪽 확인
int left = right - 1;
if (gear[left][2] == gear[right][6]) break;
else move_cmd[right] = move_cmd[left] * -1;
}
for (int j = 0; j < 4; j++) {
if (move_cmd[j] == 1) {
char temp = gear[j][7];
for (int k = 7; k >= 1; k--) {
gear[j][k] = gear[j][k - 1];
}
gear[j][0] = temp;
}
if (move_cmd[j] == -1) {
char temp = gear[j][0];
for (int k = 0; k < 7; k++) {
gear[j][k] = gear[j][k + 1];
}
gear[j][7] = temp;
}
}
}
int ret = 0;
for (int i = 0; i < 4; ++i) {
if (gear[i][0] == '1') {
ret += (1 << i);
}
}
cout << ret;
return 0;
}
728x90
Comments