본문 바로가기

분류 전체보기221

[Java] 백준 [2178] 미로 탐색 import java.util.LinkedList; import java.util.Queue; public class Solution { // 미로 탐색 - BFS 2178번 // 최단 거리 탐색 BFS static int r = 4; static int c = 6; static int[][] arr = {{1, 0, 1, 1, 1, 1}, {1, 0, 1, 0, 1, 0}, {1, 0, 1, 0, 1, 1}, {1, 1, 1, 0, 1, 1}}; static boolean[][] visit = {}; static int[] dx = {0, 0, -1, 1}; static int[] dy = {-1, 1, 0, 0}; public static void bfs(int n, int m) { Queue q =.. 2022. 12. 24.
[Block Chain] Java 실습-3 core > BlockChainStarter package core; import java.util.ArrayList; public class BlockChainStarter { public static void main(String[] args) { // TODO Auto-generated method stub Block block1 = new Block(1, null, 0, new ArrayList()); block1.mine(); block1.getInformation(); Block block2 = new Block(2, block1.getBlockHash(), 0, new ArrayList()); block2.addTransaction(new Transaction("이승엽", "홍길동", 1.5.. 2022. 12. 21.
[Block Chain] Java 실습-2 core > BlockChainStarter package core; public class BlockChainStarter { public static void main(String[] args) { // TODO Auto-generated method stub Block block1 = new Block(1, null, 0, "데이터"); // 블록 아이디, 이전 블록의 해시 값, 채굴을 위한 정답, 블록에 들어가는 데이터 block1.mine(); block1.getInformation(); Block block2 = new Block(2, block1.getBlockHash(), 0, "데이터"); block2.mine(); block2.getInformation(); Block block3 = .. 2022. 12. 21.
[Block Chain] Java 실습-1 core > BlockChainStarter package core; import util.Util; public class BlockChainStarter { public static void main(String[] args) { // TODO Auto-generated method stub // STEP 1. 해시 알고리즘은 입력 값이 조금만 바뀌어도 결과는 완전히 다른 값이 나온다. 채굴의 원리는 이러한 눈사태 효과에서 출발한다. System.out.println(Util.getHash("이승엽")); // 0c2bc0396e93dcc356680303162ced49c0fe2fed31ed1da7753113e413a2c06a System.out.println(Util.getHash("이승엽1")); .. 2022. 12. 19.
[Java] 백준 [1541] 잃어버린 괄호 public class Solution { // 잃어버린 괄호 - Greedy 1541번 public static int solution(String str) { String[] strArr1 = str.split("-"); // 문자 "-" 기준으로 split int totalSum = 0; int tempSum = 0; // strArr1 = {"55", "50+40", "20", "30+40"} for (int i = 0; i < strArr1.length; i++) { tempSum = 0; String[] strArr2 = strArr1[i].split("\\+"); // 특수문자 "+" 기준으로 split (특수문자의 경우 \\특수문자 or [특수문자]) for (int j = 0; j < s.. 2022. 12. 18.
[Java] 백준 [7570] 줄 세우기 import java.util.Arrays; public class Solution { // 줄 세우기 - DP 7570번 // 제일 앞 또는 제일 뒤로만 이동 가능 // 연속된 가장 긴 증가하는 부분 수열 이용 static int n = 7; static int[] arr = {3, 7, 5, 2, 6, 1, 4}; static int[] dp = {1, 1, 1, 1, 1, 1, 1}; public static void setLine() { int clisCnt = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < i; j++) { if (arr[i] == arr[j] + 1) { dp[i] = Math.max(dp[i], dp[j] + 1); } } } .. 2022. 12. 17.