1181번 단어 정렬
2023. 4. 3. 09:12ㆍBaekJoon
단계별로 풀어보기 - 정렬 - 8단계
https://www.acmicpc.net/problem/1181
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
bool compare(string a, string b)
{
if(a.size()==b.size())
{
return a<b;
}
else
{
return a.size()<b.size();
}
}
int main()
{
int N;
vector <string>a;
cin>>N;
for(int i=0;i<N;i++)
{
string word;
cin>>word;
a.push_back(word);
}
sort(a.begin(),a.end(),compare);
a.erase(unique(a.begin(),a.end()),a.end());
for(int i=0;i<a.size();i++)
{
cout<<a[i]<<"\n";
}
return 0;
}
'BaekJoon' 카테고리의 다른 글
11870번 좌표 압축 (0) | 2023.04.03 |
---|---|
10814번 나이순 정렬 (0) | 2023.04.03 |
11651번 좌표 정렬하기 2 (0) | 2023.04.03 |
11650번 좌표 정렬하기 (0) | 2023.04.03 |
1427번 소트인사이드 (0) | 2023.04.03 |