분류 전체보기
-
[c++] 백준 1181번 - 단어 정렬Programming/알고리즘 문제 2020. 11. 7. 00:24
# 백준 1181번 URL 1181번: 단어 정렬 첫째 줄에 단어의 개수 N이 주어진다. (1≤N≤20,000) 둘째 줄부터 N개의 줄에 걸쳐 알파벳 소문자로 이루어진 단어가 한 줄에 하나씩 주어진다. 주어지는 문자열의 길이는 50을 넘지 않는다. www.acmicpc.net 1. 길이가 짧은 것 2. 길이가 같을 경우 사전 순으로 입력할 문자열의 수 N을 먼저 입력하고, N가지의 문자열을 입력한다. 그리고 각 N개의 문자열을 위의 두 가지 조건을 만족시켜 출력하는 문제였다. 문제 풀이는 간단하다. C++ STL에서 지원하는 sort를 사용하는 대신 세번째 인수로 bool 형식의 compare라는 함수를 사용하면 된다. compare라는 함수는 길이가 string.length() 함수를 사용하여 길이가 ..