본문 바로가기
알고리즘 & 자료구조/백준

백준 1032

by 신재권 2021. 11. 23.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main1032 {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int N = Integer.parseInt(br.readLine()); //파일의 개수
		String[] file = new String[N];
		
		for(int i=0; i<N; i++){
			file[i] =  br.readLine();
		}
		
		int len = file[0].length();
		boolean[] chk = new boolean[len];
		for(int i=0; i<len; i++){
			chk[i] = true;
		}

		for(int i=0; i<len; i++){ //모두 비교
			
			char c = 0;
			for(int j=0; j<N; j++){
				char a = file[j].charAt(i);
				
				if(j == 0){
					c = a; 
					continue;
				}
				if(!chk[i] && j > 0){  
					break; 
				}
				if(a == c){ //이전꺼와 비교
					chk[i] = true;
				}else{
					chk[i] = false;
				}
				c = a; //현재꺼 저장 
			}
		}
		StringBuffer sb = new StringBuffer();
		for(int i=0; i<len; i++){
			if(chk[i]){
				sb.append(file[0].charAt(i));
			}else{
				sb.append("?");
			}
		}
		System.out.println(sb);
		
		
	}
	
	
}

'알고리즘 & 자료구조 > 백준' 카테고리의 다른 글

백준 4796  (0) 2021.11.25
백준 15685  (0) 2021.11.24
백준 2596  (0) 2021.11.22
백준 2546  (0) 2021.11.21
백준 2520  (0) 2021.11.20