Post

[BaekJoon] 25372번 - 성택이의 은밀한 비밀번호 [Java][C++]

[BaekJoon] 25372번 - 성택이의 은밀한 비밀번호 [Java][C++]

문제 링크


1. 문제 풀이


문자열의 길이를 구하는 함수를 활용하면 간단하게 해결할 수 있다.


2. 코드


1. 풀이 [Java]

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());
        for (int i = 0; i < N; i++) {
            String str = br.readLine();

            if (6 <= str.length() && str.length() <= 9) {
                bw.write("yes\n");
            } else {
                bw.write("no\n");
            }
        }

        bw.flush();
    }
}


2. 풀이 [C++]

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(false);
    cin.tie(nullptr);

    int n;
    cin >> n;

    for (int i = 0; i < n; i++) {
        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.