Post

[BaekJoon] #4999 - 아! [Java][C++]

[BaekJoon] #4999 - 아! [Java][C++]

문제 링크


1. 아이디어

첫째 줄은 재환이가 가장 길게 낼 수 있는 소리가, 둘째 줄은 의사가 듣기를 원하는 소리가 주어지며 재환이가 가장 길게 낼 수 있는 소리가 의사가 듣기를 원하는 소리보다 짧으면 진단을 내릴 수 없으므로 두 문자열의 길이를 비교 연산자로 비교하면 된다.


2. 복잡도

접근시간공간
풀이$O(N + M)$$O(N + M)$

($N$ = s1의 길이, $M$ = s2의 길이)


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 s1 = br.readLine();
        String s2 = br.readLine();

        if (s1.length() < s2.length()) {
            System.out.println("no");
        } else {
            System.out.println("go");
        }
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    string s1, s2;
    cin >> s1 >> s2;

    if (s1.size() < s2.size()) {
        cout << "no";
    } else {
        cout << "go";
    }
}

This post is licensed under CC BY 4.0 by the author.