Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return n
}

func main() {
	scanner.Split(bufio.ScanWords)

	w := nextInt()
	n := nextInt()

	numbers := make([]int, w+1)
	for i := 1; i <= w; i++ {
		numbers[i] = i
	}

	for i := 0; i < n; i++ {
		line := nextString()
		words := strings.Split(line, ",")
		a, _ := strconv.Atoi(words[0])
		b, _ := strconv.Atoi(words[1])

		numbers[a], numbers[b] = numbers[b], numbers[a]
	}

	for i := 1; i <= w; i++ {
		fmt.Println(numbers[i])
	}
}

C++: #include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int main() {
	int amd[31];
	int w,n; scanf("%d%d", &w, &n);
	for(int i = 1; i <= w; i++) amd[i]=i;
	for(int i = 0; i < n; i++) {
		int a,b; scanf("%d,%d", &a, &b);
		swap(amd[a], amd[b]);
	}
	for(int i = 1; i <= w; i++) printf("%d\n",amd[i]);
	return 0;
}

C++: #include<stdio.h>

int main(){
int tate,yoko,bou[30][2],j,x,kekka[]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30},i=0;
scanf("%d %d",&tate,&yoko);
for(j=0;j<yoko;j++){
scanf("%d , %d",&bou[j][1],&bou[j][2]);
}
for(i=1;i<tate+1;i++){
x=i;
for(j=0;j<yoko;j++){
if(bou[j][1]==x){
x=bou[j][2];
}
else if(bou[j][2]==x){
x=bou[j][1];
}
}
kekka[x-1]=i;
}
for(j=0;j<tate;j++){
printf("%d\n",kekka[j]);
}
}

C++: #include <iostream>
#include <cstdio>
using namespace std;

int main(){
  int w,n;
  int a[30],b[30],ans[100],tmp;
  cin >> w >> n;

  for(int i=0;i<n;i++)scanf("%d,%d",&a[i],&b[i]);
  

    for(int j=1;j<=w;j++){
      tmp=j;
      for(int i=0;i<n;i++){
	if(j==a[i]||j==b[i]){
	  if(j!=a[i])j=a[i];
	  else j=b[i];
	}
      }
      ans[j]=tmp;
      j=tmp;
    }
    for(int i=1;i<=w;i++)cout << ans[i]<<endl;


  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

int main(){
    int s[50]={},w,n,a,b,i;
    cin >> w;
    for(i=1;i<=w;i++){
        s[i] = i;
    }
    cin >> n;
    for(i=1;i<=n;i++){
        scanf("%d,%d",&a,&b);
        swap(s[a],s[b]);
    }
    for(int i=1;i<=w;i++){
        cout << s[i] << endl;
    }
    return 0;
}

C++: #include <iostream>

using namespace std;

void swap(int& a,int& b)
{
	int tmp = a;
	a = b;
	b = tmp;
}

int main()
{
	int w,n;
	int a,b;
	int perm[31];
	char dummy;
	
	cin >> w >> n;
	
	for (int i=1; i<=w; i++) perm[i] = i;
	
	for (int i=0; i<n; i++) {
		cin >> a >> dummy >> b;
		swap(perm[a], perm[b]);
	}
	
	for (int i=1; i<=w; i++) cout << perm[i] << endl;
	
	return 0;
}

C++: #include <iostream>
#include <utility>
#include <cstring>
#include <sstream>
using namespace std;

void swap(int*,int*,int);
int main()
{
  int w,n,i;
  cin>>w>>n;
  int *numline = new int;
  for(i=0;i<w;++i){
    numline[i]=i+1;
  }
  int *swapline = new int;
  for(i=0;i<2*n;i+=2){
    char innum[10];
    cin >>innum;
    int m=0;
    while(innum[m]!=',') ++m;
    if(m==1){
      swapline[i]=innum[0]-48;
      if(strlen(innum)-m-1==1) swapline[i+1]=innum[2]-48;
      else swapline[i+1]=10*(innum[2]-48)+(innum[3]-48);
    }
    else{
      swapline[i]=10*(innum[0]-48)+(innum[1]-48);
      if(strlen(innum)-m-1==1) swapline[i+1]=innum[3]-48;
      else swapline[i+1]=10*(innum[3]-48)+(innum[4]-48);
    }
  }
  swap(numline,swapline,n);
  for(i=0;i<w;++i){
  cout<<numline[i]<<endl;
  }
  delete numline;
  delete swapline;
  return 0;
}

void swap(int numline[],int swapline[],int n)
{
  for(int i=0;i<2*n;i+=2){
    swap(numline[swapline[i]-1],numline[swapline[i+1]-1]);
  }
}

C++: #include<iostream>
#include<stdio.h>

int main(){

  int w,n,a,b,tmp;
  std::cin >> w >> n;

  int tate[w];

  for(int i=0;i<w;i++){
    tate[i]=i+1;
  }

  for(int i=0;i<n;i++){
    scanf(" %d,%d",&a,&b);
    tmp = tate[a-1];
    tate[a-1] = tate[b-1];
    tate[b-1] = tmp;
  }

  for(int i=0;i<w;i++){
    std::cout << tate[i] << std::endl;
  }


}

C++: #include<iostream>
#include<stdio.h>

#define     MAX_COUNT_W     30
#define     MAX_COUNT_N     30

using namespace std;

void myswap(int *,int *);

int main(){
	int w,n,a,b,i;
	int *pAmida;

	// w (縦棒の本数) と n (横棒の本数) を入力
	cin >> w >> n;

	// 入力のチェック
	if((w <= 0) || (w > ((int)(MAX_COUNT_W)))){
		cerr << "縦棒の本数が範囲外です" << endl;
		return -1;
	}
	if((n <= 0) || (n > ((int)(MAX_COUNT_N)))){
		cerr << "横棒の本数が範囲外です" << endl;
		return -1;
	}

	// あみだくじ 領域の確保
	pAmida = new int[w];

	// あみだくじ 領域の初期化
	for(i=0;i<w;i++){
		*(pAmida + i) = i + 1;
	}

	// あみだくじ 処理
	for(i=0;i<n;i++){
		// 横棒の入力
		scanf("%d,%d",&a,&b);
		// 入力のチェック
		if((a <= 0) || (a > w) || (b <= 0) || (b > w)){
			cerr << "棒に来る数字が範囲外です" << endl;
			i--;
		}else{
			// 前処理
			a--;
			b--;
			// 交換
			myswap(pAmida + a,pAmida + b);
		}
	}

	// 出力
	for(i=0;i<w;i++){
		cout << *(pAmida + i) << endl;
	}

	// あみだくじ 領域の解放
	delete [] pAmida;

	return 0;
}

void myswap(int *a,int *b){
	*a += *b;
	*b -= *a;
	*b *= (-1);
	*a -= *b;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int w,n,a,b;
	int num[30];
	cin>>w>>n;
	for(int i=0;i<w;i++)num[i]=i+1;
	while(n--){
		cin>>a;
		cin.ignore(1);//改行まで最大１文字読み飛ばし
		cin>>b;
		swap(num[a-1],num[b-1]);
	}
	for(int i=0;i<w;i++)
		cout<<num[i]<<endl;
	return 0;
}

C++: #include <iostream>

int main(){
	int a,b,c,g,h;
	std::cin>>a>>b;
    int d[a];
    for(int e=1;e<=a;e++){
    	d[e]=e;
    	
	}
	for(int f=0;f<b;f++){
		std::cin>>g;
		std::cout<<",";
		std::cin>>h;
		c=d[g];
		d[g]=d[h];
		d[h]=c;
	}
	for(int i=1;i<=a;i++){
		std::cout<<d[i]<<std::endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int w,n,t[31][31],a,b;
char ch;
int main(){
  for(int i=0;i<31;i++){
    for(int j=0;j<31;j++){
      t[i][j]=j;
    }
  } 
  cin>>w>>n;
  for(int i=1;i<=n;i++){
    cin>>a>>ch>>b;
    t[i][a]=b;
    t[i][b]=a;
  }
  for(int j=1;j<=w;j++){
    a=j;
    for(int i=n;i>=0;i--){
      a=t[i][a];
    }
    cout<<a<<endl;
  }
  return 0;
}

C++: #include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

vector<int> makeRangeArray(int n)
{
        static vector<int> vec;
        for(int i = 1; i <= n; i++){
                vec.push_back(i);
        }

        return vec;
}

void exchangeInArray(vector<int>& vec, int a, int b)
{
        if(a <= 0 || b <= 0)
                throw "エラー発生";

        a--;
        b--;

        swap(vec[a],vec[b]);
}

int reader(string str, int& a, int& b)
{
        int i;

        a = 0;
        b = 0;
        for(i=0; str[i] != ','; i++)
        {
                a *= 10;
                a += str[i] - '0';
        }

        for(i++; str[i];i++){
                b *=10;
                b += str[i] - '0';
        }
}

int main()
{
        try{
                int w;
                int n;
                cin >> n;
                cin >> w;
                vector<int> vec = makeRangeArray(n);
                for(int i=0;i<w;i++){
                        int a,b;
                        string str;
                        cin >> str;
                        reader(str, a, b);
                        exchangeInArray(vec, a, b);
                }

                for(auto x:vec){
                        cout << x << endl;
                }
        }
        catch (char *str){
                cout << str << endl;
        }
}

C++: 
#include<iostream>
using namespace std;

int main(){
  int tate,yoko,n,m,a,b,c[31];
  cin>>tate;
  for(int i=1;i<=tate;i++)
    c[i]=i;
  cin>>yoko;
  for(int i=0;i<yoko;i++){
    cin>>a>>b;
    swap(c[a],c[b]);
  }
  for(int i=1;i<=tate;i++)
    cout<<c[i]<<endl;
  return 0;
}