Notice
Recent Posts
Recent Comments
Link
«   2025/07   »
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
Archives
Today
Total
관리 메뉴

Programmer

1181번 단어 정렬 본문

백준

1181번 단어 정렬

Yuwel 2020. 4. 11. 03:11
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;
vector<string> str;
string s;
int inputLength;

bool chk(string a, string b) {
	if (a.length() == b.length())
		return a < b;
	return a.length() < b.length();
}

void solve() {
	cin >> inputLength;

	for (int i = 0; i < inputLength; i++) {
		cin >> s;
		if(find(str.begin(), str.end(), s) == str.end())
			str.push_back(s);
	}
	
	sort(str.begin(), str.end(), chk);
	for (auto i : str)
		cout << i << '\n';	//endl을 쓸 경우 시간 초과

}
int main() {
	solve();
	return 0;
}

'백준' 카테고리의 다른 글

1158 요세푸스 문제  (0) 2020.04.13
3986번 좋은 단어  (0) 2020.04.04
10828번 스택  (0) 2020.04.03
10845번 큐  (0) 2020.04.02
Comments