끄적끄적 코딩
article thumbnail

정렬 문제입니다.

200보다 작거나 같은 사람이 있으므로 벡터 배열을 201개이상 만들어줍니다.
그리고 숫자에 맞는 배열에 이름을 push_back해줍니다.

sort 함수로 숫자순으로 정렬을 하고 출력해주었습니다.

 

#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <string>
#define fio ios_base::sync_with_stdio(0), cin.tie(0)
using namespace std;

int main(int argc, char *argv[])
{
	int n;
	int num = 0;
	char s[110];
	vector<string> v[210];

	cin >> n;

	for (int i = 0; i < n; ++i) {
		cin >> num;
		cin >> s;
		
		v[num].push_back(s);
	}

	for (int i = 0; i < 210; ++i) {
		for (int j = 0; j < v[i].size(); ++j) {
			cout << i << " " << v[i][j] << "\n";
		}
	}

	return 0;
}

검색 태그