코드
#include #include #include using namespace std; bool lengthsort(string x, string y){ if(x.length() != y.length()){ return x.length() < y.length(); } else return x } int main(){ int N; cin >> N; cin.ignore(); string a[20001]; for(int i = 0; i < N; i++){ cin >> a[i]; } sort(a, a+N, lengthsort); for(int i = 0; i < N; i++){ if(a[i] == a[i-1]) continue; else{ cout << a[i] << endl; } } return 0; } |
설명
string 배열 a에 단어들을 입력받습니다.
sort함수를 이용해 단어들을 글자수 순, 글자수가 같다면 사전순 으로 배열하고 이를 출력합니다.
같은 단어는 continue하고, 같지 않은 단어만 출력하도록 반복문을 설정합니다.
'하루하나코딩' 카테고리의 다른 글
백준 1874번 : 스택수열 c++ (0) | 2022.12.31 |
---|---|
백준 2667번 : 단지번호붙이기 c++ (0) | 2022.12.30 |
백준 2606번 : 바이러스 c++ (0) | 2022.12.29 |
백준 2178번 : 미로 탐색 c++ (0) | 2022.12.28 |
백준 1260번 : DFS와 BFS c++ (0) | 2022.12.27 |