문제 링크입니다: www.acmicpc.net/problem/1547
1547번: 공
첫째 줄에 컵의 위치를 바꾼 횟수 M이 주어지며, M은 50보다 작거나 같은 자연수이다. 둘째 줄부터 M개의 줄에는 컵의 위치를 바꾼 방법 X와 Y가 주어지며, X번 컵과 Y번 컵의 위치를 서로 바꾸는 것
www.acmicpc.net
간단한 구현 문제였습니다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main(void) | |
{ | |
ios_base::sync_with_stdio(0); | |
cin.tie(0); | |
int M; | |
cin >> M; | |
int ball = 1; | |
for (int m = 0; m < M; m++) | |
{ | |
int X, Y; | |
cin >> X >> Y; | |
if (X == ball || Y == ball) | |
{ | |
ball = (X == ball ? Y : X); | |
} | |
} | |
cout << ball << "\n"; | |
return 0; | |
} |


개발환경:Visual Studio 2017
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > BOJ' 카테고리의 다른 글
백준 1703번 생장점 (0) | 2021.04.04 |
---|---|
백준 1598번 꼬리를 무는 숫자 나열 (0) | 2021.04.04 |
백준 1333번 부재중 전화 (0) | 2021.04.04 |
백준 1284번 집 주소 (0) | 2021.04.04 |
백준 21335번 Another Eruption (0) | 2021.04.02 |