[BaekJoon] #25372 - 성택이의 은밀한 비밀번호 [Java][C++]
[BaekJoon] #25372 - 성택이의 은밀한 비밀번호 [Java][C++]
1. 아이디어
문자열의 길이를 구하는 함수를 활용해 6자 이상 9자 이하인지 판단하면 간단하게 해결할 수 있다.
2. 복잡도
| 접근 | 시간 | 공간 |
|---|---|---|
| 풀이 | $O(N)$ | $O(1)$ |
($N$ = 입력값 n)
3. 코드
풀이 [Java][C++]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int n = Integer.parseInt(br.readLine());
while (n-- > 0) {
String s = br.readLine();
if (6 <= s.length() && s.length() <= 9) {
bw.write("yes\n");
} else {
bw.write("no\n");
}
}
bw.flush();
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
while (n--) {
string s;
cin >> s;
if (6 <= s.size() && s.size() <= 9) {
cout << "yes\n";
} else {
cout << "no\n";
}
}
}
This post is licensed under CC BY 4.0 by the author.