전체 글
-
[백준] 16953번 : A -> B - 자바(JAVA)알고리즘/백준 2022. 8. 22. 00:01
https://www.acmicpc.net/problem/16953 16953번: A → B 첫째 줄에 A, B (1 ≤ A < B ≤ 109)가 주어진다. www.acmicpc.net 문제 해석 정수 A와 B가 주어집니다. A로 B를 만드려고 하는데 두가지 연산을 수행할 수 있습니다. A * 2 A * 10 + 1 이때 필요한 연산의 최솟값을 구해보려고 합니다. 문제 풀이 전 설계 Queue를 사용하고 Number 객체를 만들어 (현재 수, 연산의 step)을 관리합니다. 이때 수는 항상 커집니다. 따라서 Queue에 add하기 전에 현재 수가 B보다 큰 경우에는 add하지 않습니다. 그리고 B가 10억까지 주어질 수 있습니다. A를 연산하는 과정에 overflow가 발생할 수 있어서 long 타입을 ..
-
[백준] 1181번 : 단어 정렬 - 자바(JAVA)알고리즘/백준 2022. 8. 21. 00:01
https://www.acmicpc.net/problem/1181 1181번: 단어 정렬 첫째 줄에 단어의 개수 N이 주어진다. (1 ≤ N ≤ 20,000) 둘째 줄부터 N개의 줄에 걸쳐 알파벳 소문자로 이루어진 단어가 한 줄에 하나씩 주어진다. 주어지는 문자열의 길이는 50을 넘지 않는다. www.acmicpc.net 문제 해석 알파벳으로 이루어진 N개의 문자열을 정렬해야 합니다. 길이가 짧은 것부터 길이가 같으면 사전 순으로 문제 풀이 전 설계 람다를 활용하여 Comparator를 구현하고 스트림을 활용하여 Set 을 List로 변환하고자 합니다. 코드 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStr..
-
JPA Paging 적용하기프로젝트/미디어 스트리밍 서버 프로젝트 2022. 8. 20. 19:25
페이징이란? 만약 게시글이 100만 건이라면 어떻게 될까요? 한 화면에서 모든 게시글을 보여줄 수 없기 때문에 페이지를 나눠서 게시글을 보여주는 방식으로 해결합니다. 그러면 100만건의 10만 개의 페이지로 나누어 10건씩 데이터를 전송할 수 있습니다. JPA와 페이징 JPA를 사용하면 PagingAndSortingRepository 인터페이스를 통해 쉽게 페이징을 구현할 수 있습니다. public interface PagingAndSortingRepository extends CrudRepository { Page findAll(Pageable pageable); } 이미 findAll이 구현되어 있고 Pageable이라는 객체를 받아 Page를 반환합니다. 이때 Controller에서 받을때 Page..
-
[백준] 1018번 : 체스판 다시 칠하기 - 자바(JAVA)알고리즘/백준 2022. 8. 20. 00:01
https://www.acmicpc.net/problem/1018 1018번: 체스판 다시 칠하기 첫째 줄에 N과 M이 주어진다. N과 M은 8보다 크거나 같고, 50보다 작거나 같은 자연수이다. 둘째 줄부터 N개의 줄에는 보드의 각 행의 상태가 주어진다. B는 검은색이며, W는 흰색이다. www.acmicpc.net 문제 해석 N*M의 보드가 주어집니다. 이 보드는 흰색 또는 검정색으로 칠해져있습니다. 여기에서 8x8 크기의 체스판으로 잘라낸 후 체스판처럼 칠하고자 합니다. 이때 체스판처럼 이미 칠해져 있으면 가장 좋은 경우입니다. 다시 칠해야 하는 정사각형의 최소 개수를 구하세요 문제 풀이 전 설계 8 x 8 크기의 검정색으로 시작하는 체스판, 흰색으로 시작하는 체스판을 미리 그려놓습니다. 그리고 보..
-
Json with MultipartFile프로젝트/미디어 스트리밍 서버 프로젝트 2022. 8. 19. 15:03
개요 MultipartFile을 통해 S3에 저장하던 중 제목과 내용도 함께 저장해야 하는 요구사항을 처리하고자 했습니다. 가장 간단하게 든 생각으로 "DTO를 만들어서 처리하자"였습니다. data class FileRequest( val subject : String, val content : String, val file : MultipartFile, ) { } 하지만 API를 호출하여 전달하려고 하는데 MultipartFile은 Json으로 어떻게 보내지?라는 생각이 들었습니다. @RequestPart 활용하기 API에서 consume할 MediaType을 지정해주는 방식을 사용해서 하나의 API에서 Json과 MultipartFile을 한 번에 전달받을 수 있습니다. @PostMapping(con..
-
[Spring + Kotlin]Kotest와 MockK를 활용한 테스트 코드 작성프로젝트/미디어 스트리밍 서버 프로젝트 2022. 8. 19. 12:52
개요 코틀린과 스프링을 같이 쓰게 되면 junit5를 주로 사용하곤 했습니다. 하지만 Kotest라는 테스트 프레임워크의 인기가 높아지고 있습니다. Kotest란? 확장 Assertions와 통합 Property test를 통해 코틀린을 위한 유연하고 우아한 다중 플랫폼 오픈 소스 테스트 프레임워크입니다. 여러 개의 독립 실행형 하위 프로젝트로 나뉘며, 각 하위 프로젝트는 독립적으로 사용할 수 있습니다. Test framework Assertions library Property testing kotest를 사용하여 세 가지 프로젝트를 모두 함께 사용할 수 있습니다. 또는 다른 프로젝트와 함께 선택하여 사용할 수 있습니다. 예를 들어 Junit과 함께 Assertions library를 사용할 수 있습니..
-
[백준] 111720번 : 숫자의 합 - 자바(JAVA)알고리즘/백준 2022. 8. 19. 00:01
https://www.acmicpc.net/problem/11720 11720번: 숫자의 합 첫째 줄에 숫자의 개수 N (1 ≤ N ≤ 100)이 주어진다. 둘째 줄에 숫자 N개가 공백없이 주어진다. www.acmicpc.net 문제 해석 54321 이렇게 이루어진 문자열을 모두 더해서 출력하는 문제입니다. 문제 풀이 전 설계 문자열을 하나씩 쪼개서 int로 바꾸고 모두 더하면 됩니다. 코드 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; public class Main_11720_숫자의합 { public static void main(Stri..
-
스트림 활용Java/모던자바인액션요약 2022. 8. 18. 00:01
필터링 filter 메서드 스트림 인터페이스는 filter 메서드를 지원합니다. filter 메서드는 프레디케이트를 인수로 받아 프레디케이트와 일치하는 모든 요소를 포함하는 스트림을 반환합니다.(중간 연산) List vegetarianMenu = menu.stream() .filter(Dish::isVegetarian) .collect(toList()); distinct 메서드 중복을 필터링합니다. List numbers = Arrays.asList(1, 2, 3, 1, 2, 3, 4, 5, 6); numbers.stream() .filter(i -> i % 2 == 0) .distinct() .forEach(System.out::println); 프레디케이트를 이용한 슬라이싱 takeWhile 활용 3..