개인공부/코딩테스트
백준 1181: 단어 정렬
Itsumo
2023. 1. 30. 22:44
1181번: 단어 정렬
첫째 줄에 단어의 개수 N이 주어진다. (1 ≤ N ≤ 20,000) 둘째 줄부터 N개의 줄에 걸쳐 알파벳 소문자로 이루어진 단어가 한 줄에 하나씩 주어진다. 주어지는 문자열의 길이는 50을 넘지 않는다.
www.acmicpc.net
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int main(void)
{
int TestCase = 0;
cin >> TestCase;
priority_queue<string, vector<string>, greater<string>> pq[50];
for (int i = 0; i < TestCase; ++i)
{
string str;
cin >> str;
pq[str.size()-1].push(str);
}
for (int i = 0; i < 50; ++i)
{
vector<string> Outputstring;
while (!pq[i].empty())
{
bool IsSameWord = false;
for (int j = 0; j < Outputstring.size(); ++j)
{
if (Outputstring[j] == pq[i].top())
IsSameWord = true;
}
if (IsSameWord == false)
{
cout << pq[i].top() << '\n';
Outputstring.push_back(pq[i].top());
}
pq[i].pop();
}
}
return 0;
}
|
cs |