재밌는 시뮬레이션 구현 문제 ~
이 문제도 골드 5 인데 이거는 솔직히 . . 인구이동보다 훨씬 할만함 ...
왜 다 같은 골드 5인지 참 의문이네
그냥 간단히 해서, 이전의 바퀴에 대한 정보랑,
이후의 바퀴에 대한 정보를 저장
이전 바퀴들을 보고 이후 바퀴에 저장하는 식으로 ..
정말 정직하게 clockwise, counter-clockwise로 돌려주면 된다.
string으로 받으면 정말 간단 ~
좀 더 예쁘게 정리할 수 있었겠지만 ..
//
// Created by 신성준 on 2023/03/26.
//
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string wheel[5];
string after_wheel[5];
for(int i = 1; i < 5; i++) {
cin >> wheel[i];
} //N은 0, S는 1
int K;
cin >> K;
while(K--) {
int num, direction;
cin >> num >> direction; //direction : 1 = clockwise / -1 = counter clock
vector<int> left;
vector<int> right;
for (int i = num; i > 0; i--) {
left.push_back(i);
}
for (int i = num; i < 5; i++) {
right.push_back(i);
}
string origin_wheel = wheel[num];
int origin_direction = direction;
//지목당한 바퀴 처리
string now_wheel = wheel[num];
string a = now_wheel;
if (direction == 1) {
char b = a.back();
a.pop_back();
a = b + a;
after_wheel[num] = a;
}
else if (direction == -1){
char b = a.front();
a.erase(0, 1);
a = a + b;
after_wheel[num] = a;
}
//left처리
now_wheel = wheel[num];
int now_direction = origin_direction * -1;
int no_circle = 0;
for (int i = 1; i < left.size(); i++) {
now_wheel = wheel[left[i]];
if(now_wheel[2] == wheel[left[i-1]][6] || no_circle){
after_wheel[left[i]] = now_wheel;
no_circle = 1;
}
else {
a = now_wheel;
if (now_direction == 1) {
char b = a.back();
a.pop_back();
a = b + a;
after_wheel[left[i]] = a;
} else if (now_direction == -1) {
char b = a.front();
a.erase(0, 1);
a = a + b;
after_wheel[left[i]] = a;
}
now_direction = now_direction * -1;
}
}
//right 처리
now_direction = origin_direction * -1;
no_circle = 0;
for (int i = 1; i < right.size(); i++){
now_wheel = wheel[right[i]];
if(now_wheel[6] == wheel[right[i-1]][2] || no_circle){
after_wheel[right[i]] = now_wheel;
no_circle = 1;
}
else {
a = now_wheel;
if (now_direction == 1) {
char b = a.back();
a.pop_back();
a = b + a;
after_wheel[right[i]] = a;
} else if (now_direction == -1) {
char b = a.front();
a.erase(0, 1);
a = a + b;
after_wheel[right[i]] = a;
}
now_direction = now_direction * -1;
}
}
for(int i = 1; i < 5; i++){
wheel[i] = after_wheel[i];
}
}
int score = 0;
if(after_wheel[1][0] == '1'){
score += 1;
}
if(after_wheel[2][0] == '1'){
score += 2;
}
if(after_wheel[3][0] == '1'){
score += 4;
}
if(after_wheel[4][0] == '1'){
score += 8;
}
cout << score;
}
좋네요