coding study/baekjoon
[java] 1032. 명령 프롬프트
yeoonii
2023. 8. 13. 15:43
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
String[] words = new String[N];
for (int i=0 ; i< words.length ; i++) {
words[i] = br.readLine();
}
int minLength = Integer.MAX_VALUE;
for (String word : words) {
minLength = Math.min(minLength, word.length());
}
StringBuilder output = new StringBuilder();
for (int i=0 ; i<minLength ; i++) {
char currentChar = words[0].charAt(i);
boolean isSame = true;
for (String word : words) {
if (word.charAt(i) != currentChar) {
isSame = false;
break;
}
}
if (isSame) {
output.append(currentChar);
} else {
output.append('?');
}
}
System.out.println(output.toString());
br.close();
}
}