1547 공
문제 링크
다른 사람 풀이
#include <iostream>
using namespace std;
int ch;
int main(void) {
scanf("%d", &ch);
int n = 1;
for (int i = 0; i < ch; i++)
{
int t1, t2;
scanf("%d %d", &t1, &t2);
if (n == t1 || n == t2) {
if (n == t1)
n = t2;
else
n = t1;
}
}
printf("%d", n);
return 0;
}
내 풀이
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> mv;
int pos[3] = { 1, 2, 3 };
int main() {
int n;
cin >> n;
mv.resize(n);
for (int i = 0; i < n; i++)
cin >> mv[i].first >> mv[i].second;
for (auto a : mv) {
int i, j;
for (i = 0; i < 3; i++)
if (pos[i] == a.first) {
pos[i] = a.second;
break;
}
for (j = 0; j < 3; j++)
if (pos[j] == a.second && (i != j)) {
pos[j] = a.first;
break;
}
}
cout << pos[0] << "\n";
}
댓글남기기