728x90
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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; public class Main { private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); private static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); public static void main(String[] args) throws IOException{ String[] str = br.readLine().split(" "); int N = stoi(str[0]); int M = stoi(str[1]); String[] dnaArr = new String[N]; for (int i=0; i<N; i++) dnaArr[i] = br.readLine(); int max; int[] alpArr; StringBuilder sb = new StringBuilder(); int hd = 0; for (int i=0; i<M; i++) { max = 0; alpArr = new int[26]; for (int j = 0; j < N; j++) { int curr = dnaArr[j].charAt(i)-'A'; alpArr[curr]++; if(alpArr[curr]>max) max = alpArr[curr]; } for (int j=0; j<alpArr.length; j++) { if(max==alpArr[j]) { sb.append((char)(j+'A')); break; } } hd += N-max; } sb.append("\n"+hd); System.out.println(sb.toString()); // bw.write(""); // bw.flush(); // bw.close(); } private static int stoi(String input) { return Integer.parseInt(input); } } | cs |
'알고리즘 풀이 > 백준' 카테고리의 다른 글
★ [백준][Java] 1373번 2진수 8진수 (문자열) (0) | 2021.09.30 |
---|---|
★ [백준][Java] 10820번 문자열 분석 (문자열) (0) | 2021.09.30 |
★ [백준][Java] 9663번 N-Queen (백트래킹, 브루트 포스) (0) | 2021.09.27 |
[백준][Java] 2493번 탑 (스택, 구현) #2 (0) | 2021.09.27 |
★ [백준][Java] 5525번 IOIOI (문자열, 누적합) (0) | 2021.09.24 |