문제 바로가기> 백준 4458번: 첫 글자를 대문자로
C++을 이용한 풀이이다. cin
은 '\n'를 변수에 담지 않고 입력버퍼에 남겨두고, getline
은 '\n'를 변수에 담기 때문에 cin.ignore()
를 사용해서 입력 버퍼를 비워주는 과정이 필요하다!
#include<iostream>
using namespace std;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int N; cin >> N; cin.ignore();
while(N--){
string str;
getline(cin, str);
if(96<str[0]) str[0]-=32;
cout << str << '\n';
}
}
python을 이용한 풀이이다. upper()
함수를 이용하여 쉽게 풀 수 있다!
def solution():
import sys
input = sys.stdin.readline
N = int(input())
for i in range(N):
s = input().rstrip()
s = s[0].upper() + s[1:]
print(s)
solution()