[BaekJoon] #15000 - CAPS [Java][C++]
[BaekJoon] #15000 - CAPS [Java][C++]
1. 아이디어
알파벳 소문자들로 주어진 문자열의 각 문자를 대문자로 출력하면 되는 문제로 내장 함수를 활용하거나 아스키 코드 값 차이를 활용하면 된다.
2. 복잡도
| 접근 | 시간 | 공간 |
|---|---|---|
| 풀이 | $O(N)$ | $O(N)$ |
($N$ = s의 길이)
3. 코드
풀이 [Java][C++]
1
2
3
4
5
6
7
8
9
10
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
System.out.println(s.toUpperCase());
}
}
toUpperCase 메서드로 대문자로 변환된 문자열을 얻을 수 있다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
string s;
cin >> s;
for (char c : s) {
cout << (char)(c - 'a' + 'A');
}
}
This post is licensed under CC BY 4.0 by the author.