※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 13224번 문제인 Chop Cup이다.
문제는 아래 링크를 확인하자.
https://www.acmicpc.net/problem/13224
13224번: Chop Cup
Oisín is amateur magician and is big fan of Chop Cup routine which involves three cups face down and one ball underneath one of the cups. He's only started to practice the trick and wants to test out if you can follow where the ball is without any tricks
www.acmicpc.net
주어지는 A, B, C의 움직임을 각 주어진 위치의 두 원소를 서로 바꿔주는 것으로 구현해 문제의 상황을 그대로 시뮬레이션하는 것으로 문제를 해결할 수 있다.
특히 swap 함수를 이용하면 문제의 상황을 손쉽게 구현할 수 있다.
아래는 제출한 소스코드이다.
#include <iostream>
#include <algorithm>
using namespace std;
int arr[3] = { 1,0,0 };
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
string s; cin >> s;
for (auto letter : s) {
if (letter == 'A') swap(arr[0], arr[1]);
else if (letter == 'B') swap(arr[1], arr[2]);
else swap(arr[0], arr[2]);
}
for (int i = 0; i < 3; i++) {
if (arr[i]) cout << i + 1;
}
}
728x90
'BOJ' 카테고리의 다른 글
[BOJ 13222 // C++] Matches (0) | 2022.11.25 |
---|---|
[BOJ 13223 // C++] 소금 폭탄 (0) | 2022.11.25 |
[BOJ 16175 // C++] General Election (0) | 2022.11.24 |
[BOJ 15239 // C++] Password check (0) | 2022.11.24 |
[BOJ 13240 // C++] Chessboard (0) | 2022.11.24 |