✔️ 나의 답-> 맞음
import java.util.*;
public class p12 {
public static String solution(int in ,String input){
input= input.replace("#","1");
input= input.replace("*","0");
int startNum =-1;
String answer="";
String [] input_ = input.split("");
for(int i=0;i<in;i++){
int sum=0;
startNum +=7;
for( int j=0;j<7;j++){
sum += Integer.parseInt(input_[startNum-j])*Math.pow(2,j);
}
answer+=String.valueOf((char)sum);
}
return answer;
}
public static void main(String[] args){
Scanner kb = new Scanner(System.in);
int in = kb.nextInt();
String input = kb.next();
System.out.println(solution(in,input));
}
}
✔️ 강의 답
import java.util.*;
public class p12 {
public static String solution(int in ,String input){
String answer="";
for(int i=0;i<in;i++) {
String tmp = input.substring(0,7).replace("#","1").replace("*","0");
int num = Integer.parseInt(tmp,2);
answer+=(char)num;
input=input.substring(7);
}
return answer;
}
public static void main(String[] args){
Scanner kb = new Scanner(System.in);
int in = kb.nextInt();
String input = kb.next();
System.out.println(solution(in,input));
}
}