https://www.acmicpc.net/problem/1181
1181번: 단어 정렬
첫째 줄에 단어의 개수 N이 주어진다. (1 ≤ N ≤ 20,000) 둘째 줄부터 N개의 줄에 걸쳐 알파벳 소문자로 이루어진 단어가 한 줄에 하나씩 주어진다. 주어지는 문자열의 길이는 50을 넘지 않는다.
www.acmicpc.net
[ 백준 1181번 단어 정렬 소스 코드 ]
#include <iostream>
#include <vector>
#include <algorithm>
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(){
vector <string> a;
string temp= "";
int N;
cin>>N;
for(int i=0;i<N;i++){
string word;
cin>>word;
a.push_back(word);
}
sort(a.begin(),a.end(),compare);
for(int i=0;i<N;i++){
if(temp==a[i])continue;
cout<<a[i]<<'\n';
temp=a[i];
}
return 0;
}
'백준 문제풀이' 카테고리의 다른 글
백준 2568번 전깃줄 소스코드 (0) | 2021.07.31 |
---|---|
백준 2606번 바이러스 - 유니온파인드 (0) | 2021.07.10 |
백준 2617번 - 구슬찾기 소스 코드 (0) | 2021.06.04 |
백준 1406번 - 에디터 소스 코드 (0) | 2021.05.02 |
백준 2458번 - 키순서 소스 코드 (0) | 2021.05.02 |