[백준][Java] 1969번 DNA (문자열, 브루트 포스)

[백준][Java] 1969번 DNA (문자열, 브루트 포스)

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( "

" + hd); System . out . println (sb. toString ()); // bw.write(""); // bw.flush(); // bw.close(); } private static int stoi( String input) { return Integer. parseInt (input); } } Colored by Color Scripter

from http://aig2029.tistory.com/309 by ccl(A) rewrite - 2021-09-29 06:28:05