matthew as a q.

競技プログラミングメイン

AOJ0011Drawing Lots

シミュレーション。やるだけ

コンマで区切られた数値の読み込み方

getlineでコンマを終端子として、文字列として読み込む
→string型文字列で管理してるものをchar型で渡す(c_str())
→atoi関数でchar型文字列をint型で渡す

REのとき疑うべき点

途中でクラッシュ(ex.配列足りてない)、mainの返り値

#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>

using namespace std;

typedef long long ll;

int main(){
    int w, n;
    int a[30];
    cin >> w >> n;
    for (int i = 0; i < w; ++i)
    {
        a[i] = i+1;
    }
    //指定されたものをスワップしていくだけ
    string f, l;
    for (int i = 0; i < n; ++i)
    {
        getline(cin, f, ',');
        getline(cin, l, '\n');
        int fi = atoi(f.c_str());
        int li = atoi(l.c_str());
        swap(a[fi-1], a[li-1]);
    }
    for (int i = 0; i < w; ++i)
    {
        cout << a[i] << endl;
    }
	return 0;
}