import java.util.*;
class Main {
public String solution(int num, String str) {
String answer = "";
for(int i = 0; i < num; i++) {
// 0~7까지 자르고 # -> 1, * -> 0으로 치환
String tmp = str.substring(0, 7).replace("#", "1").replace("*", "0");
// 2진수 -> 10진수 변환
int n = Integer.parseInt(tmp, 2);
// 아스키코드 -> 문자 변환
answer += (char)n;
// 7글자씩 자르기
str = str.substring(7);
}
return answer;
}
public static void main(String []args) {
Main T = new Main();
Scanner kb = new Scanner(System.in);
int num = kb.nextInt();
String str = kb.next();
System.out.println(T.solution(num, str));
}
}
문자 -> 숫자
char ch = sc.nextLine().charAt(0);
int num = (int)ch;
입력 : a
출력 : 97
숫자 -> 문자
int num = sc.nextInt();
char ch = (char)num;
입력 : 65
출력 : A
10진수 -> 2진수
int a = 25;
System.out.println(Integer.toString(a, 2));
2진수 -> 10진수
String a = "110011";
System.out.println(Integer.parseInt(a, 2));
import java.util.*;
class Main {
public String solution(int num, String str) {
String answer = "";
for(int i = 0; i < num; i++) {
String tmp = str.substring(0, 7).replace("#", "1").replace("*", "0");
int n = Integer.parseInt(tmp, 2);
answer += (char)n;
str = str.substring(7);
}
return answer;
}
public static void main(String []args) {
Main T = new Main();
Scanner kb = new Scanner(System.in);
int num = kb.nextInt();
String str = kb.next();
System.out.println(T.solution(num, str));
}
}
'코딩테스트 > 기초' 카테고리의 다른 글
15. 가위 바위 보 (0) | 2024.12.08 |
---|---|
14. 보이는 학생 (0) | 2024.12.08 |
11. 문자열 압축 (1) | 2024.12.07 |
10. 가장 짧은 문자거리 (0) | 2024.12.06 |
9. 숫자만 추출 (1) | 2024.12.03 |