# Link
https://www.acmicpc.net/problem/2840
2840번: 행운의 바퀴
첫째 줄에 마지막 회전에서 화살표가 가리키는 문자부터 시계방향으로 바퀴에 적어놓은 알파벳을 출력한다. 이때, 어떤 글자인지 결정하지 못하는 칸은 '?'를 출력한다. 만약, 상덕이가 적어놓
www.acmicpc.net
# Code - C++
//
// BOJ
// ver.C++
//
// Created by GGlifer
//
// Open Source
#include <iostream>
#include <cstring>
using namespace std;
#define endl '\n'
#define len(x) (int)(x).length()
#define size(x) (int)(x).size()
#define str(x) to_string(x)
#define error logic_error("line " + str(__LINE__))
// Set up : Definitions
/* None */
// Set up : Global Variables
/* None */
// Set up : Functions Declaration
/* None */
int main()
{
// Set up : I/O
ios::sync_with_stdio(false);
cin.tie(nullptr);
// Set up : Input
int N, K;
cin >> N >> K;
int S[K];
char C[K];
for (int i=0; i<K; i++) {
cin >> S[i] >> C[i];
}
// Process
bool isUsed['Z'+1];
memset(isUsed, false, sizeof(isUsed));
string A(N, '?');
A[0] = C[K-1];
isUsed[A[0]] = true;
int idx = 0;
bool isPossible = true;
for (int i=K-2; i>=0; i--) {
int s = S[i+1];
char c = C[i];
idx += s, idx %= N;
if (A[idx] == '?' && not(isUsed[c])) {
A[idx] = c;
isUsed[c] = true;
} else if (A[idx] == c) {
continue;
} else {
isPossible = false;
break;
}
}
// Control : Output
cout << ((isPossible) ? A : "!") << endl;
}
// Helper Functions
/* None */
지적, 조언, 첨언 모두 환영합니다!!!
'Problem Solving > 백준' 카테고리의 다른 글
| [ Problem Solving :: 백준 ] 8983 / 사냥꾼 (0) | 2021.11.13 |
|---|---|
| [ Problem Solving :: 백준 ] 2075 / N번째 큰 수 (0) | 2021.11.12 |
| [ Problem Solving :: 백준 ] 1647 / 도시 분할 계획 (0) | 2021.11.02 |
| [ Problem Solving :: 백준 ] 2872 / 우리집엔 도서관이 있어 (0) | 2021.11.02 |
| [ Problem Solving :: 백준 ] 10040 / 투표 (0) | 2021.10.30 |