[BOJ] 1181 단어 정렬

Time Lapse :None

1181.cpp

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
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cstdio>

using namespace std;

#define MAXSIZE 600

vector <string> arr;
string temp;
int N;


bool compare(const string &a,const string &b)
{
if (a.length()==b.length())
return a<b;
else
return a.length()<b.length();
}

int main(void)
{
cin >> N;
for (int i = 0; i < N; i++)
{
cin >> temp;
arr.push_back(temp);
}
sort(arr.begin(), arr.end(),compare);

arr.erase(unique(arr.begin(), arr.end()),arr.end());

for (int i = 0; i < arr.size(); i++)
{
cout << arr[i] << endl;
}
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/23/PS/BOJ/1181/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.