자료구조와 알고리듬 With Java/[Study] BAEKJOON 프로그래머스 CodeUp LeetCode 40

2022-06-29 [4회차] 알고리즘 스터디

1. substring의 index 찾기 - String haystack에 대해서 String needle이 haystack의 한 부분을 차지하는 경우 그 index를 반환하라. - 부분 문자열이 아닌 경우는 -1을 반환하라 - 포인터를 써서 풀도록 문제를 가져오셨는데 내가 단순하게 substr으로 풀었다. 포인터로 푸는 부분도 복습! 출처: https://leetcode.com/problems/implement-strstr/ Implement strStr() - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your n..

2022-06-22 [3회차] 알고리즘 스터디

1.스도쿠 - DFS, 재귀함수 (골드 4) https://www.acmicpc.net/problem/2580 2580번: 스도쿠 스도쿠는 18세기 스위스 수학자가 만든 '라틴 사각형'이랑 퍼즐에서 유래한 것으로 현재 많은 인기를 누리고 있다. 이 게임은 아래 그림과 같이 가로, 세로 각각 9개씩 총 81개의 작은 칸으로 이루 www.acmicpc.net Sol) 스터디원 코드 - 스터디원 블로그 /** 0 4 0 0 0 0 2 0 0 0 6 0 0 0 5 0 0 0 2 0 5 0 8 0 0 0 7 0 0 6 0 0 0 0 0 0 5 0 7 0 0 1 9 0 0 0 0 0 0 4 0 0 1 0 0 0 0 3 0 0 0 0 8 0 2 0 0 0 0 0 0 0 9 0 1 0 0 4 7 0 0 * 0 0 0 ..

Baek joon 5052 전화 번호

Ex) 전화 번호 목록 - sort와 startsWith를 이용한다. - phone_book[i].startsWith(phone_book[i-1]) : phone_book[i-1]가 phone_book[i]의 접두사인지 확인한다. - Arrays.sort(배열명): 배열을 오름차순으로 정렬한다. Sol) import java.util.*; class Solution { public boolean solution(String[] phone_book) { Arrays.sort(phone_book); // sort로 정렬하면 119와 1195524421이 옆자리에 정렬된다. for(int i = 1; i < phone_book.length; ++i){ //따라서, 바로 옆자리에 있는 수가 접두사인지 확인하면 ..

Baekjoon 9375번 패션왕 신혜빈

Ex) 각 테스트 케이스에 대해 해빈이가 알몸이 아닌 상태로 의상을 입을 수 있는 경우를 출력하시오. 해빈이는 패션에 매우 민감해서 한번 입었던 옷들의 조합을 절대 다시 입지 않는다. 예를 들어 오늘 해빈이가 안경, 코트, 상의, 신발을 입었다면, 다음날은 바지를 추가로 입거나 안경대신 렌즈를 착용하거나 해야한다. 해빈이가 가진 의상들이 주어졌을때 과연 해빈이는 알몸이 아닌 상태로 며칠동안 밖에 돌아다닐 수 있을까? 첫째 줄에 테스트 케이스가 주어진다. 테스트 케이스는 최대 100이다.- - 각 테스트 케이스의 첫째 줄에는 해빈이가 가진 의상의 수 n(0 ≤ n ≤ 30)이 주어진다. - 다음 n개에는 해빈이가 가진 의상의 이름과 의상의 종류가 공백으로 구분되어 주어진다. 같은 종류의 의상은 하나만 입을..

Backjoon 7576 BFS 토마토

Ex) 며칠 후에 상자 안의 토마토가 모두 익는지 구하라. 창고에 보관되는 토마토들 중에는 잘 익은 것도 있지만, 아직 익지 않은 토마토들도 있을 수 있다. 보관 후 하루가 지나면, 익은 토마토들의 인접한 곳에 있는 익지 않은 토마토들은 익은 토마토의 영향을 받아 익게 된다. 하나의 토마토의 인접한 곳은 왼쪽, 오른쪽, 앞, 뒤 네 방향에 있는 토마토를 의미한다. 대각선 방향에 있는 토마토들에게는 영향을 주지 못하며, 토마토가 혼자 저절로 익는 경우는 없다고 가정한다. 철수는 창고에 보관된 토마토들이 며칠이 지나면 다 익게 되는지, 그 최소 일수를 알고 싶어 한다. 토마토를 창고에 보관하는 격자모양의 상자들의 크기와 익은 토마토들과 익지 않은 토마토들의 정보가 주어졌을 때, 며칠이 지나면 토마토들이 모두..

BFS 미로 찾기 (small)

Ex) /* 5 5 #S### #...# #.#.# #.... ###G# */ import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; public class Maze { static int MAX_COUNT = 101; static char [][] AdjMatrix = new char[MAX_COUNT][MAX_COUNT]; static int [][] VisitMatrix = new int[MAX_COUNT][MAX_COUNT]; static int Width; static int Height; static int DIRECTION = 4; static int [][] DirMatrix = {{-1, 0}, {1, ..

BFS 알리바바 미로

Ex) package first; /* [입력] 5 5 10110 00010 01010 01000 00011 [출력] 9 */ import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; public class AlibabaMaze { static int MAX_COUNT = 101; static int DIRECTION = 4; static int[][] DirMatrix = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; static int ColumnCnt; static int RowCnt; static int cnt = 0; static int[][] AdjMatrix = new int[MAX_COUN..

BFS 마법의 비료

/* 5 4 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 1 */ package first; import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; public class MagiFertilizer0 { static int MAX_COUNT = 101; static int [][] AdjMatrix = new int[MAX_COUNT][MAX_COUNT]; static int [][] VisitMatrix = new int[MAX_COUNT][MAX_COUNT]; static int Width; static int Height; static int DIRECTION = 4; static int [..

Java 2차원 맵 탐색을 위한 BFS

package first; import java.security.KeyPair; import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; import java.lang.*; public class TwoDimensionDFS { static int MAX_COUNT = 101; static int DIRECTION = 4; static int[][] DirMatrix = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; static int ColumnCnt; static int RowCnt; static int cnt = 0; static int[][] Array = new int[MAX_COUNT][2];..

Code up 4503 바이러스 (BFS)

Ex) import java.util.HashSet; import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; import java.util.Set; public class BFSpractice0 { static int MAX_COUNT = 101; static int [][] AdjMatrix = new int [MAX_COUNT][MAX_COUNT]; static int[] VisitMatrix = new int[MAX_COUNT]; static int VertaxCount, EdgeCount; static Queue queue = new LinkedList(); static Set set = new HashSet()..