http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0011&lang=jp
#include <iostream> #include <vector> using namespace std; int main (int argc, char * const argv[]) { // insert code here... int w; while (cin >> w) { if (w == 0) { break; } int r[w]; for (int i=0; i < w; i++) { r[i] = i+1; } //入力 int n; cin >> n; int a[n],b[n]; char tmp; for (int i=0; i < n; i++) { cin >> a[i]; cin >> tmp; cin >> b[i]; } //計算 for (int i=0; i < n; i++) { int hoge = r[a[i] - 1]; r[a[i] - 1] = r[b[i] - 1]; r[b[i] - 1] = hoge; } for (int i=0; i < w; i++) { cout << r[i] <<endl; } break; } return 0; }