[BaekJoon] #25372 - 성택이의 은밀한 비밀번호 [Java][C++][Python]
[BaekJoon] #25372 - 성택이의 은밀한 비밀번호 [Java][C++][Python]
1. 아이디어
문자열이 현관문 비밀번호로 사용 가능한지 판정하는 문제로, 길이가 6 이상 9 이하이면 yes, 아니면 no를 출력한다.
2. 코드
풀이 [Java][C++][Python]
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";
}
}
}
1
2
3
4
5
6
7
8
import sys
input = sys.stdin.readline
n = int(input())
for _ in range(n):
s = input().rstrip()
print("yes" if 6 <= len(s) <= 9 else "no")
sys.stdin.readline은 줄바꿈까지 읽어 오므로 rstrip으로 지웠다. 지우지 않으면 길이가 1 더 커져 9자리가 10자리로 계산된다.
This post is licensed under CC BY 4.0 by the author.