Search

단어 정렬

Created
2021/03/23 01:58
문제 번호
1181
카테고리
문자열

Memo

Code

제출 날짜

@10/9/2020

메모리

4492 KB

시간

60 ms
#include <iostream> #include <vector> #include <algorithm> #define endl "\n" int numberOfWords; std::vector<std::string> words; std::vector<std::string>::iterator iter; std::vector<std::string>::iterator uniqueIter; void inputAction() { std::cin >> numberOfWords; for (int i = 0; i < numberOfWords; i++) { std::string temp; std::cin >> temp; words.push_back(temp); } } bool compare(const std::string &a, const std::string &b) { if (a.length() == b.length()) { return a < b; } else { return a.length() < b.length(); } } void outputAction() { for (iter = words.begin(); iter != uniqueIter; iter++) { std::cout << *iter << endl; } } void solution() { inputAction(); std::sort(words.begin(), words.end(), compare); uniqueIter = std::unique(words.begin(), words.end()); outputAction(); } int main(void) { solution(); return 0; }
C++
복사