[BaekJoon] #2744 - 대소문자 바꾸기 [Java][C++]
[BaekJoon] #2744 - 대소문자 바꾸기 [Java][C++]
1. 아이디어
대소문자를 바꾸어 출력하는 문제로 내장 함수를 활용해도 되고 아스키 코드의 범위를 활용해도 된다.
2. 복잡도
| 접근 | 시간 | 공간 |
|---|---|---|
| 풀이 | $O(N)$ | $O(N)$ |
($N$ = s의 길이)
3. 코드
풀이 [Java][C++]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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();
for (char c : s.toCharArray()) {
if (Character.isLowerCase(c)) {
System.out.print(Character.toUpperCase(c));
} else {
System.out.print(Character.toLowerCase(c));
}
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#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) {
if (islower(c)) {
cout << (char)toupper(c);
} else {
cout << (char)tolower(c);
}
}
}
This post is licensed under CC BY 4.0 by the author.