반응형
4458번: 첫 글자를 대문자로
문제
문장을 읽은 뒤, 줄의 첫 글자를 대문자로 바꾸는 프로그램을 작성하시오.
입력
첫째 줄에 줄의 수 N이 주어진다. 다음 N개의 줄에는 문장이 주어진다. 각 문장에 들어있는 글자의 수는 30을 넘지 않는다. 모든 줄의 첫 번째 글자는 알파벳이다.
출력
각 줄의 첫글자를 대문자로 바꾼뒤 출력한다.
예제 입력 1
5
powdered Toast Man
skeletor
Electra Woman and Dyna Girl
she-Ra Princess of Power
darth Vader
예제 출력 1
Powdered Toast Man
Skeletor
Electra Woman and Dyna Girl
She-Ra Princess of Power
Darth Vader
자료구조
① 배열: input
알고리즘
① 문자열 str의 toUppercase() 함수를 이용해서 첫 글자를 소문자에서 대문자로 변환한다.
② 나머지 부분은 그대로 유지한다.
소스 코드 1
const fs = require('fs');
const filePath = process.platform === 'linux' ? '/dev/stdin' : './input.txt';
const [, ...input] = fs.readFileSync(filePath).toString()
.trim()
.split("\n");
for (let str of input) {
const firstChar = str[0].toUpperCase();
console.log(firstChar + str.slice(1));
}
120ms
소스 코드 2
const fs = require('fs');
const filePath = process.platform === 'linux' ? '/dev/stdin' : './input.txt';
const [, ...input] = fs.readFileSync(filePath).toString()
.trim()
.split("\n");
input.map((str) => console.log(str[0].toUpperCase() + str.slice(1)));
120ms
✔ 출처
반응형
'JS 코딩테스트 > 문제풀이' 카테고리의 다른 글
[자바스크립트] 2744 대소문자 바꾸기 (0) | 2024.01.21 |
---|---|
[자바스크립트] 11721 열 개씩 끊어 출력하기 (0) | 2024.01.21 |
[자바스크립트] 2675 문자열 반복 (0) | 2024.01.20 |
[자바스크립트] 9086 문자열 (0) | 2024.01.20 |
[자바스크립트] 10808 알파벳 개수 (1) | 2024.01.19 |