프로그래밍/알고리즘

백준 알고리즘 1032번 : 명령 프롬프트 (JAVA)

김민쏭 2019. 10. 19. 04:35

C++ : https://1nnovator.tistory.com/30 

 

REPOSITORY

 

1nnovator.tistory.com

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package java_algorithm;
 
import java.util.Scanner;
 
public class Baekjoon_1032 {
 
    public static void main(String[] args) {
 
        Scanner sc = new Scanner(System.in);
 
        int n = sc.nextInt();
 
        String[] str = new String[n];
 
        for (int i = 0; i < n; i++) {
 
            str[i] = sc.next();
 
        }
 
        boolean dif = false;
 
        for (int i = 0; i < str[0].length(); i++) {
            dif = false;
            for (int j = 0; j < n - 1; j++) {
 
                if (str[j].charAt(i) != str[j + 1].charAt(i)) {
                    dif = true;
                    break;
                }
 
            }
 
            if (dif)
                System.out.print("?");
            else
                System.out.print(str[0].charAt(i));
 
        }
 
    }
 
}
 
cs

 

Scanner가 낯설다.

boolean 변수를 사용하여 풀었다.