Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 프로젝트캠프
- 개발
- STATE
- 프론트엔드 개발
- 프론트엔드
- 스나이퍼팩토리
- 상태 관리 라이브러리
- React Query
- sucoding
- frontend
- 웅진씽크빅
- 유데미
- 수코딩
- 리액트프로젝트
- React
- 공식문서
- tanstack query
- TypeScript
- Server State
Archives
- Today
- Total
yunicornlab
백준 1181번 단어 정렬하기 JavaScript 풀이 본문
반응형
백준 1181번 단어 정렬하기 문제를 자바스크립트로 풀어보았다.
https://www.acmicpc.net/problem/1181
let fs = require('fs');
let input = fs.readFileSync('/dev/stdin').toString().trim().split('\n');
let n = Number(input[0]);
let words = [];
for (let i=1; i<n+1; i++) {
// 중복 제거
if (!words.includes(input[i])) words.push(input[i])
}
function sortWords(a, b) {
if (a.length !== b.length) return a.length - b.length;
else {
if (a < b) return -1;
else if (a > b) return 1;
else return 0;
};
}
words.sort(sortWords)
let answer = "";
for (let i=0; i<words.length; i++) {
answer += words[i] + '\n'
}
console.log(answer)
반응형
'Coding Test > Practice' 카테고리의 다른 글
백준 10814번 나이순 정렬 JavaScript 풀이 (0) | 2024.07.20 |
---|---|
백준 18870번 좌표 압축 JavaScript 풀이 (0) | 2024.07.20 |
백준 11651번 좌표 정렬하기 2 JavaScript 풀이 (0) | 2024.07.20 |
백준 11650번 좌표 정렬하기 JavaScript 풀이 (0) | 2024.07.20 |
백준 11004번 K번째 수 JavaScript 풀이 (0) | 2024.07.20 |