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

IT Blog404

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค[Java] - (Level2)์Šคํ‚ฌํŠธ๋ฆฌ https://programmers.co.kr/learn/courses/30/lessons/49993 ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr ์ฝ”๋“œ class Solution { public static int solution(String skill, String[] skill_trees) { int answer = 0; for(int i=0; i C๋ฅผ๋ฐฐ์šฐ๊ณ  B๋ฅผ ๋ฐฐ์›Œ์•ผํ•จ */ else if(index < skill.indexOf(s)){ check = false; break; } } if(check)answer ++; } return answer;.. 2020. 3. 19.
ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค[Java] - (Level2)์†Œ์ˆ˜ ๋งŒ๋“ค๊ธฐ https://programmers.co.kr/learn/courses/30/lessons/12977 ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr ์ฝ”๋“œ class Solution { public static boolean isPrime(int num){ if(num == 2) return true; for(int i=2; i 2020. 3. 18.
[Codeforces] 1257A: Two Rival Students https://codeforces.com/problemset/problem/1257/A Problem - 1257A - Codeforces codeforces.com ์ฝ”๋“œ import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int t = scan.nextInt(); for(int tc=0; tc= n) System.out.println(n-1); else System.out.println(diff); } scan.close(); } } ํ’€์ด x ์ˆ˜๋งŒํผ ๋‘ ํ•™์ƒ์˜ ๊ฑฐ๋ฆฌ๋ฅผ ๋ฒŒ๋ฆด ์ˆ˜ ์žˆ๊ณ , ๋‘ ํ•™์ƒ์˜ ๊ฑฐ๋ฆฌ๊ฐ€ ์ตœ๋Œ€๊ฐ€ ๋˜๋„๋ก ๋งŒ๋“ค๊ธฐ. 1) ์ฃผ.. 2020. 3. 18.
ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค[Java] - (Level2)์˜์–ด ๋๋ง์ž‡๊ธฐ https://programmers.co.kr/learn/courses/30/lessons/12981 ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr ์ฝ”๋“œ import java.util.*; class Solution { public int[] solution(int n, String[] words) { int[] answer = new int[2]; List list = new ArrayList(); boolean flag = true; for(int i=0; i0 && words[i-1].charAt(words[i-1].length()-1) != wor.. 2020. 3. 18.
ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค[Java] - (Level2)์˜ฌ๋ฐ”๋ฅธ ๊ด„ํ˜ธ https://programmers.co.kr/learn/courses/30/lessons/12909 ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr ์‹œ๊ฐ„ ์ดˆ๊ณผ ์ฝ”๋“œ import java.util.*; class Solution { boolean solution(String s) { boolean answer = true; Stack stack = new Stack(); if(s.charAt(0) == ')') return false; for(int i=0; i pop()์„ ํ•ด์ฃผ๊ณ , ๊ทธ ๋ฐ˜๋Œ€์˜ ๊ฒฝ์šฐ '(' ๊ฐ€ ์™”์„๊ฒฝ์šฐ ์Šคํƒ์— ๋„ฃ์–ด์ค€๋‹ค -> push() ๋งˆ์ง€.. 2020. 3. 17.
ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค[Java] - (Level2)์ ํ”„์™€ ์ˆœ๊ฐ„ ์ด๋™ https://programmers.co.kr/learn/courses/30/lessons/12980 ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr ์ฝ”๋“œ public class Solution { public int solution(int n) { int ans = 0; while(n!=1){ if(n%2 == 0) n /= 2; else{ n -= 1; ans ++; } } ans ++; return ans; } } ํ’€์ด ๊ทœ์น™์„ ์ฐพ์•„๋ณด๋ฉด ์‰ฝ๊ฒŒ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋‹ค. K์นธ ์ ํ”„ํ•˜๋ฉด K๋งŒํผ์˜ ๊ฑด์ „์ง€ ์‚ฌ์šฉ๋Ÿ‰์ด ๋“ค๊ณ , (ํ˜„์žฌ์œ„์น˜ * 2) ๋งŒํผ ์ˆœ๊ฐ„์ด๋™ ํ•˜๋ฉด ๊ฑด์ „์ง€๋Š”.. 2020. 3. 17.
ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค[Java] - (Level3)์ตœ๊ณ ์˜ ์ง‘ํ•ฉ https://programmers.co.kr/learn/courses/30/lessons/12938 ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr ์ฝ”๋“œ import java.util.*; class Solution { public int[] solution(int n, int s) { if(n > s) return new int[]{-1}; int[] answer = new int[n]; for(int i=0; i 13/3 = 4 ์ด๋‹ค. ๋”ฐ๋ผ์„œ answer ๋ฐฐ์—ด์˜ ๋ชจ๋“  ์š”์†Œ์— 4๋ฅผ ์ €์žฅํ•œ๋‹ค. - answer = [4, 4, 4] - s%n ===> 13.. 2020. 3. 17.
ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค[Java] - (Level3)ํ•˜๋…ธ์ด์˜ ํƒ‘ https://programmers.co.kr/learn/courses/30/lessons/12946 ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr ์ฝ”๋“œ class Solution { public static int[][] answer; public static int x = 0; // n๊ฐœ๋ฅผ other๊ธฐ๋‘ฅ์„ ์‚ฌ์šฉํ•ด from -> to๋กœ ์˜ฎ๊ธฐ๊ธฐ public static void hanoi(int n, int from, int other, int to){ if(n == 0) return; hanoi(n-1, from, to, other); // n-1๊ฐœ์˜ .. 2020. 3. 17.
ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค[Java] - (Level3)๋ฐฉ๋ฌธ ๊ธธ์ด https://programmers.co.kr/learn/courses/30/lessons/49994 ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr ์ฝ”๋“œ class Solution { // U,D,R,L - ์œ„,์•„๋ž˜,์˜ค๋ฅธ์ชฝ,์™ผ์ชฝ ์ˆœ public static int[] dx = {0, 0, 1, -1}; public static int[] dy = {-1, 1, 0, 0}; // ๋งต์˜ ํฌ๊ธฐ = -5 ~ 5๊นŒ์ง€์ด๋ฏ€๋กœ 11x11 public static boolean[][][][] visit = new boolean[11][11][11][11]; public .. 2020. 3. 17.
[Codeforces] 1005A: Tanya and Stairways https://codeforces.com/problemset/problem/1005/A Problem - 1005A - Codeforces codeforces.com ์ฝ”๋“œ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws IOException { BufferedReader bf = new BufferedReader(new I.. 2020. 3. 17.
๋ฐ˜์‘ํ˜•