๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
728x90
๋ฐ˜์‘ํ˜•

Coding Test40

[Baekjoon] 14889.์Šคํƒ€ํŠธ์™€ ๋งํฌ/Java - Silver1 โ“๋ฌธ์ œhttps://www.acmicpc.net/problem/14889๐Ÿ“Œ์œ ํ˜•๋ฐฑํŠธ๋ž˜ํ‚น โœ๐Ÿปํ’€์ด๊ณ ๋ฅด์ง€ ์•Š์€ ์„ ์ˆ˜๋ผ๋ฉด true๋กœ ๋ฐ”๊พธ๊ณ  ์„ ํƒํ•œ ์„ ์ˆ˜ + 1 ๋ถ€ํ„ฐ ์ถ”์ . n/2๋ช…์„ ๊ณ ๋ฅด๊ณ  ์Šคํƒ€ํŠธํŒ€ ์ ์ˆ˜์™€ ๋งํฌ ํŒ€ ์ ์ˆ˜๋ฅผ ๊ณ„์‚ฐ. ๋‘ ๊ณ„์‚ฐ์˜ ์ฐจ์˜ ์ ˆ๋Œ“๊ฐ’๊ณผ ์ตœ์†Ÿ๊ฐ’์„ ๋น„๊ตํ•˜์—ฌ ๊ฐ€์žฅ ์ฐจ๊ฐ€ ์ž‘์€ ์ตœ์†Ÿ๊ฐ’ ์ฐพ๊ธฐ. ๐Ÿ’ป์ฝ”๋“œimport java.util.*; import java.io.*; public class Main { static int n; static int min = Integer.MAX_VALUE; static int[][] s; static boolean[] visited; static void backtracking(int len, int idx) { if (len == n / 2) { int start = 0.. 2024. 9. 29.
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ์šฐ์œ ์™€ ์š”๊ฑฐํŠธ๊ฐ€ ๋‹ด๊ธด ์žฅ๋ฐ”๊ตฌ๋‹ˆ/MySQL - Lv.4 โ“๋ฌธ์ œ ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”.programmers.co.kr๐Ÿ“Œ์œ ํ˜• SELECT, GROUP BYโœ๐Ÿปํ’€์ด์šฐ์œ ๋ฅผ ๊ตฌ๋งคํ•œ CART_ID๋“ค ์ค‘์— CART_ID๊ฐ€ ํ•ด๋‹นํ•˜๊ณ  ์š”๊ฑฐํŠธ๋„ ๊ตฌ๋งคํ•œ CART_ID๋งŒ ์ถœ๋ ฅ.๐Ÿ’ป์ฝ”๋“œSELECT CART_IDFROM CART_PRODUCTSWHERE CART_ID IN (SELECT CART_ID FROM CART_PRODUCTS WHERE NAME = 'Milk') AND NAME = 'Yogurt'GROUP BY CART_ID 2024. 9. 29.
[Baekjoon] 15649.N๊ณผ M (1)/Java - Silver3 โ“๋ฌธ์ œhttps://www.acmicpc.net/problem/15649๐Ÿ“Œ์œ ํ˜•Backtracking โœ๐Ÿปํ’€์ด๋ฐฉ๋ฌธํ•œ ์ˆซ์ž๊ฐ€ ์•„๋‹ˆ๋ผ๋ฉด true๋กœ ๋ฐ”๊พผ ํ›„ result์— ์‚ฝ์ž…. result์˜ ๊ธธ์ด๊ฐ€ m๊ณผ ๊ฐ™์•„์ง€๋ฉด ์ถœ๋ ฅ ํ›„ returnํ•˜๊ณ  result์—์„œ ์ œ์ผ ๋งˆ์ง€๋ง‰ ์ˆซ์ž๋ฅผ ์ œ๊ฑฐ. ์ด๋ฅผ n๊นŒ์ง€ ๋ฐ˜๋ณต. ๐Ÿ’ป์ฝ”๋“œimport java.util.*; import java.io.*; public class Main { static int n; static int m; static boolean[] visited; static ArrayList result = new ArrayList(); static BufferedReader r = new BufferedReader(new InputStreamReader(System.i.. 2024. 9. 29.
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ์ฃผ์‹๊ฐ€๊ฒฉ/Java - Lv.2 โ“๋ฌธ์ œ ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”.programmers.co.kr๐Ÿ“Œ์œ ํ˜•์Šคํƒ ๋˜๋Š” ํ ๋˜๋Š” ๋‹จ์ˆœ ๋ฐ˜๋ณต๋ฌธโœ๐Ÿปํ’€์ดํ˜„์žฌ ์ฃผ์‹๊ฐ€๊ฒฉ์ด ์‹œ๊ฐ„์ด ์ง€๋‚˜๋ฉด์„œ ๋ฐ”๋€ ๊ฐ€๊ฒฉ์ด ํ˜„์žฌ ๊ฐ€๊ฒฉ๊ณผ ๊ฐ™๊ฑฐ๋‚˜ ํฌ๋‹ค๋ฉด ์‹œ๊ฐ„์„ ๊ณ„์† 1์”ฉ ์ฆ๊ฐ€.ํ˜„์žฌ ๊ฐ€๊ฒฉ๋ณด๋‹ค ์ž‘์•„์ง„๋‹ค๋ฉด ๋ฐ˜๋ณต๋ฌธ์„ ๋ฉˆ์ถค.๐Ÿ’ป์ฝ”๋“œ/** ๋ฐ˜๋ณต๋ฌธ์„ ์‚ฌ์šฉํ•œ ํ’€์ด**/import java.util.*;class Solution { public int[] solution(int[] prices) { int[] answer = new int[prices.length]; for(int i = 0; i prices[.. 2024. 9. 29.
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ์กฐ๊ฑด์— ๋งž๋Š” ์‚ฌ์šฉ์ž ์ •๋ณด ์กฐํšŒํ•˜๊ธฐ/MySQL - Lv.3 โ“๋ฌธ์ œ ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”.programmers.co.kr๐Ÿ“Œ์œ ํ˜•์ง‘๊ณ„, ๋ฌธ์ž์—ดโœ๐Ÿปํ’€์ด CITY, STREET_ADDRESS1, STREET_ADDRESS2๋ฅผ ๋ชจ๋‘ ์—ฐ๊ฒฐํ•˜์—ฌ ์ „์ฒด์ฃผ์†Œ๋กœ ์ถœ๋ ฅ๋˜๋„๋ก ํ•˜๋ผ๊ณ  ํ•˜์˜€์œผ๋ฏ€๋กœ concat ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์—ฐ๊ฒฐ. SUBSTRING์„ ์ด์šฉํ•˜์—ฌ TLNO ๋ฌธ์ž์—ด์„ 3, 4, 4๊ฐœ๋กœ ๋‚˜๋ˆ„์–ด ์ค‘๊ฐ„์— '-'๋ฅผ ๋„ฃ์–ด xxx-xxxx-xxxxํ˜•ํƒœ๋กœ ์ถœ๋ ฅ๋˜๋„๋ก ํ•จ.๐Ÿ’ป์ฝ”๋“œSELECT USER_ID, NICKNAME, CONCAT(CITY, ' ', STREET_ADDRESS1, ' ', STREET_ADDRESS2) AS '์ „์ œ์ฃผ์†Œ', CONC.. 2024. 9. 28.
[Baekjoon] 28278. ์Šคํƒ 2/Java - Silver4 โ“๋ฌธ์ œhttps://www.acmicpc.net/problem/28278๐Ÿ“Œ์œ ํ˜•์Šคํƒโœ๐Ÿปํ’€์ด1๋ฒˆ ๋ช…๋ น์–ด์˜ ๊ณต๋ฐฑ ๋’ค ์˜ค๋Š” ์ˆซ์ž๋Š” ์Šคํƒ์— push.2๋ฒˆ ๋ช…๋ น์–ด ์ž…๋ ฅ ์‹œ stack.empty()๋ผ๋ฉด -1 ์•„๋‹ˆ๋ผ๋ฉด stack.pop()์œผ๋กœ ์Šคํƒ์—์„œ ๋นผ๋Š” ๋™์‹œ์— ์ถœ๋ ฅ.3๋ฒˆ ๋ช…๋ น์–ด ์ž…๋ ฅ ์‹œ stack.size()๋กœ ํฌ๊ธฐ ์ถœ๋ ฅ.4๋ฒˆ ๋ช…๋ น์–ด ์ž…๋ ฅ ์‹œ stack.empty()๋ผ๋ฉด 1 ์•„๋‹ˆ๋ฉด 0 ์ถœ๋ ฅ.5๋ฒˆ ๋ช…๋ น์–ด ์ž…๋ ฅ ์‹œ stack.empty()๋ผ๋ฉด -1 ์•„๋‹ˆ๋ฉด stack.peek()์œผ๋กœ stack์˜ top ๊ฐ’ ์ถœ๋ ฅ.๐Ÿ’ป์ฝ”๋“œimport java.util.*;import java.io.*;public class Main { static int n; static BufferedReader r = new Buffer.. 2024. 9. 28.
728x90
๋ฐ˜์‘ํ˜•