반응형
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 |
Tags
- ip
- Crawling
- Node.js
- 가천대
- 크롤링
- javascript
- 쉬운 문제
- 레벨 1
- 백준
- socket
- 프로그래머스
- 문자열
- 알고리즘
- HTTP
- 자바스크립트
- Nestjs
- HTTP 완벽 가이드
- dp
- dfs
- 타입 챌린지
- 수학
- 프로그래머스 레벨 2
- BFS
- 소켓
- TCP
- type challenge
- 그래프
- typescript
- 타입스크립트
- Algorithm
Archives
- Today
- Total
kakasoo
[node.js] 대소문자 바꾸기 ( 백준 2744번 ) 본문
반응형
// 백준 2744번 대소문자 바꾸기를 풀었습니다.
const readline = require("readline");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
rl.on("line", (line) => {
main(line);
rl.close();
}).on("close", () => process.exit());
/**
*
* @param {string} line
*/
const main = (line) => {
let answer = "";
for (let i = 0; i < line.length; i++) {
if (
"a".charCodeAt(0) <= line[i].charCodeAt(0) &&
line[i].charCodeAt(0) <= "z".charCodeAt(0)
) {
answer += line[i].toUpperCase();
} else {
answer += line[i].toLowerCase();
}
}
console.log(answer);
};
대소문자 바꾸기는 간단한 문제이다.
CharCodeAt()을 이용해서 문자열의 특정 인덱스를 숫자로 변환할 수 있다.
자바스크립트에서는 대소문자를 바꿀 때 toUpperCase, toLowerCase를 사용하면 된다.
반응형
'프로그래밍 > 알고리즘 풀이' 카테고리의 다른 글
[node.js] 골드바흐의 추측 ( 백준 6588번 ) (0) | 2021.04.07 |
---|---|
[node.js] 소수 찾기 ( 백준 1978번 ) (0) | 2021.04.07 |
[node.js] 홀수 ( 백준 2576번 ) (0) | 2021.04.06 |
[node.js] 최댓값 ( 백준 2566번 ) (0) | 2021.04.06 |
[node.js] 점수 계산 ( 백준 2506번 ) (0) | 2021.04.06 |