728x90
정렬 문제입니다.
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;
}
'알고리즘' 카테고리의 다른 글
[C++] 백준 3009번 네 번째 점 (0) | 2019.08.31 |
---|---|
[C++] 백준 2217번 로프 (0) | 2019.08.31 |
[C++] 백준 1181번 단어 정렬 (0) | 2019.08.31 |
[C++] 백준 11651번 좌표 정렬하기 2 (0) | 2019.08.30 |
[C++] 백준 11650번 좌표 정렬하기 (0) | 2019.08.30 |