Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- 자바
- 투포인터
- SWEA
- 문제해결
- 코딩테스트
- 운동기록
- dfs
- oracle
- greedy
- 알고리즘
- SQL
- 문제풀이
- 코테
- 시뮬레이션
- 건강
- 러닝일지
- DP
- 프로그래머스
- COS PRO
- MySQL
- 이분탐색
- binary search
- 백준
- math
- BOJ
- priorityqueue
- 문자열
- db
- BFS
- Java
Archives
- Today
- Total
슈콩
[SWEA] 단순 2진 암호코드 본문




단위 별로 시작점 존재하지 않음 -> 앞에서 부터 시도 가능, 뒤쪽 부터 코드 찾기 가능 (2가지)
[문제]
https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV15FZuqAL4CFAYD
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
[소스 코드]
import java.util.*;
import java.io.*;
public class Solution {
static HashMap<String,Integer> hm;
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
int T = Integer.parseInt(br.readLine());
hm = new HashMap<>();
hm.put("0001101", 0);
hm.put("0011001", 1);
hm.put("0010011", 2);
hm.put("0111101", 3);
hm.put("0100011", 4);
hm.put("0110001", 5);
hm.put("0101111", 6);
hm.put("0111011", 7);
hm.put("0110111", 8);
hm.put("0001011", 9);
for(int tc=1;tc<=T;tc++) {
st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int m = Integer.parseInt(st.nextToken());
String[] map = new String[n];
int answer = 0;
for(int i=0;i<n;i++) {
map[i] = br.readLine();
}
out:
for(int i=0;i<n;i++) {
if(map[i].contains("1")) {
for(int j=0;j<=m-56;j++) {
if(map[i].substring(j,j+7).contains("1")) {
answer = check(map[i].substring(j,j+56));
if(answer!=0) break out;
}
}
}
}
System.out.println("#"+tc+" "+answer);
}
}
private static int check(String nums) {
int odd = 0;
int even = 0;
for(int i=0;i<56;i+=7) {
String code = nums.substring(i,i+7);
if(!hm.containsKey(code)) return 0;
int num = hm.get(code);
if(i%2==0) {
odd += num;
}
else {
even += num;
}
}
int sum = odd + even;
if((odd*3 + even) % 10 == 0) return sum;
return 0;
}
}'Algorithms > SWEA' 카테고리의 다른 글
| [SWEA] 3일차 - String (0) | 2025.11.10 |
|---|---|
| [SWEA] 0/1 Knapsack (0) | 2025.11.10 |
| [SWEA] 오목 판정 (0) | 2025.11.09 |
| [SWEA] 7일차 - 암호생성기 (0) | 2025.11.09 |
| [SWEA] 재미있는 오셀로 게임 (3) | 2025.11.07 |