Algorithm - 암호

Algorithm - 암호

public class Main {

public static void main( String [] args) throws IOException {

Scanner in = new Scanner ( System . in );

StringBuilder builder = new StringBuilder();

int max = in .nextInt();

char arr [] = new char [max];

String input = in .next();

int start = 0 ;

int end = 0 ;

for ( int i = 0 ; i < max; i + + ) {

start = (i * 7 ); // 문자열의 자를 시작점을 계산해줌

end = 7 * (i + 1 ); // 문자열의 자를 마지막점을 계산해줌

String sliceText = input. substring (start, end);

String temp = "" ;

for ( int j = 0 ; j < sliceText. length (); j + + ) {

if (sliceText. charAt (j) = = '#' ) {

temp + = '1' ;

}

if (sliceText. charAt (j) = = '*' ) {

temp + = '0' ;

}

}

// 2진수를 10진수로 변환

arr[i] = ( char ) Integer. parseInt (temp, 2 );

}

for ( int i = 0 ; i < arr. length ; i + + ) {

builder.append(arr[i]);

}

System . out . println (builder);

}

}

from http://kdg-is.tistory.com/200 by ccl(A) rewrite - 2021-09-14 23:01:55