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

IT Blog404

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค[Java] - (Level2)ํฐ์ผ“๋ชฌ https://programmers.co.kr/learn/courses/30/lessons/1845?language=java ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr ์ฝ”๋“œ import java.util.*; class Solution { public int solution(int[] nums) { int answer = 0; List list = new ArrayList(); list.add(nums[0]); // nums[] ๋ฐฐ์—ด์˜ ์ค‘๋ณต์ œ๊ฑฐ for(int i=1; i ๊ฐ€์งˆ ์ˆ˜ ์žˆ๋Š” ์ข…๋ฅ˜๋Š” ํ•œ๊ฐ€์ง€ 3)์˜ ๊ฒฝ์šฐ, ์ค‘๋ณต์„ ์ œ๊ฑฐํ•˜๊ณ  ๋‚˜๋ฉด [1, 2, 3,.. 2020. 3. 13.
ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค[Java] - (Level2)๋‹ค์Œ ํฐ ์ˆซ์ž https://programmers.co.kr/learn/courses/30/lessons/12911?language=java ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr ์ฝ”๋“œ class Solution { // n์„ 2์ง„์ˆ˜๋กœ ๋ณ€ํ™˜ํ–ˆ์„ ๋•Œ 1์˜ ๊ฐฏ์ˆ˜ ์ฐพ๊ธฐ public static int oneNum(int num) { int count = 0; while(num != 0) { if(num%2 != 0) count ++; num /= 2; } return count; } public int solution(int n) { int answer = 0; fo.. 2020. 3. 13.
[Codeforces] 721A: One-dimensional Japanese Crossword https://codeforces.com/problemset/problem/721/A Problem - 721A - Codeforces codeforces.com ์ฝ”๋“œ import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); String str = scan.next(); int blackCount = 0;// ์—ฐ์†๋œ ๊ฒ€์ • ์‚ฌ๊ฐํ˜•์˜ ํ›„ List list = new ArrayList(); for(int i=0; i 2020. 3. 13.
[๋ฐฑ์ค€] 1057๋ฒˆ: ํ† ๋„ˆ๋จผํŠธ(๊ตฌํ˜„, ์ˆ˜ํ•™) https://www.acmicpc.net/problem/1057 1057๋ฒˆ: ํ† ๋„ˆ๋จผํŠธ ๊น€์ง€๋ฏผ์€ N๋ช…์ด ์ฐธ๊ฐ€ํ•˜๋Š” ์Šคํƒ€ ํ† ๋„ˆ๋จผํŠธ์— ์ง„์ถœํ–ˆ๋‹ค. ํ† ๋„ˆ๋จผํŠธ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ง„ํ–‰๋œ๋‹ค. ์ผ๋‹จ N๋ช…์˜ ์ฐธ๊ฐ€์ž๋Š” ๋ฒˆํ˜ธ๊ฐ€ 1๋ฒˆ๋ถ€ํ„ฐ N๋ฒˆ๊นŒ์ง€ ๋ฐฐ์ •๋ฐ›๋Š”๋‹ค. ๊ทธ๋Ÿฌ๊ณ  ๋‚œ ํ›„์— ์„œ๋กœ ์ธ์ ‘ํ•œ ๋ฒˆํ˜ธ๋ผ๋ฆฌ ์Šคํƒ€๋ฅผ ํ•œ๋‹ค. ์ด๊ธด ์‚ฌ๋žŒ์€ ๋‹ค์Œ ๋ผ์šด๋“œ์— ์ง„์ถœํ•˜๊ณ , ์ง„ ์‚ฌ๋žŒ์€ ๊ทธ ๋ผ์šด๋“œ์—์„œ ๋–จ์–ด์ง„๋‹ค. ๋งŒ์•ฝ ๊ทธ ๋ผ์šด๋“œ์˜ ์ฐธ๊ฐ€์ž๊ฐ€ ํ™€์ˆ˜๋ช…์ด๋ผ๋ฉด, ๋งˆ์ง€๋ง‰ ๋ฒˆํ˜ธ๋ฅผ ๊ฐ€์ง„ ์ฐธ๊ฐ€์ž๋Š” ๋‹ค์Œ ๋ผ์šด๋“œ๋กœ ์ž๋™ ์ง„์ถœํ•œ๋‹ค. ๋‹ค์Œ ๋ผ์šด๋“œ์—์„  ๋‹ค์‹œ ์ฐธ๊ฐ€์ž์˜ ๋ฒˆํ˜ธ๋ฅผ 1๋ฒˆ๋ถ€ํ„ฐ ๋งค๊ธด๋‹ค. ์ด๋•Œ, ๋ฒˆํ˜ธ๋ฅผ ๋งค๊ธฐ๋Š” ์ˆœ์„œ๋Š” ์ฒ˜์Œ www.acmicpc.net ์ฝ”๋“œ import java.util.Scanner; public class Main { public static void main(Str.. 2020. 3. 12.
[๋ฐฑ์ค€] 2979๋ฒˆ: ํŠธ๋Ÿญ ์ฃผ์ฐจ(๊ตฌํ˜„, ์‹œ๋ฎฌ๋ ˆ์ด์…˜) https://www.acmicpc.net/problem/2979 2979๋ฒˆ: ํŠธ๋Ÿญ ์ฃผ์ฐจ ๋ฌธ์ œ ์ƒ๊ทผ์ด๋Š” ํŠธ๋Ÿญ์„ ์ด ์„ธ ๋Œ€ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค. ์˜ค๋Š˜์€ ํŠธ๋Ÿญ์„ ์ฃผ์ฐจํ•˜๋Š”๋ฐ ๋น„์šฉ์ด ์–ผ๋งˆ๋‚˜ ํ•„์š”ํ•œ์ง€ ์•Œ์•„๋ณด๋ ค๊ณ  ํ•œ๋‹ค. ์ƒ๊ทผ์ด๊ฐ€ ์ด์šฉํ•˜๋Š” ์ฃผ์ฐจ์žฅ์€ ์ฃผ์ฐจํ•˜๋Š” ํŠธ๋Ÿญ์˜ ์ˆ˜์— ๋”ฐ๋ผ์„œ ์ฃผ์ฐจ ์š”๊ธˆ์„ ํ• ์ธํ•ด ์ค€๋‹ค. ํŠธ๋Ÿญ์„ ํ•œ ๋Œ€ ์ฃผ์ฐจํ•  ๋•Œ๋Š” 1๋ถ„์— ํ•œ ๋Œ€๋‹น A์›์„ ๋‚ด์•ผ ํ•œ๋‹ค. ๋‘ ๋Œ€๋ฅผ ์ฃผ์ฐจํ•  ๋•Œ๋Š” 1๋ถ„์— ํ•œ ๋Œ€๋‹น B์›, ์„ธ ๋Œ€๋ฅผ ์ฃผ์ฐจํ•  ๋•Œ๋Š” 1๋ถ„์— ํ•œ ๋Œ€๋‹น C์›์„ ๋‚ด์•ผ ํ•œ๋‹ค. A, B, C๊ฐ€ ์ฃผ์–ด์ง€๊ณ , ์ƒ๊ทผ์ด์˜ ํŠธ๋Ÿญ์ด ์ฃผ์ฐจ์žฅ์— ์ฃผ์ฐจ๋œ ์‹œ๊ฐ„์ด ์ฃผ์–ด์กŒ์„ ๋•Œ, ์ฃผ์ฐจ ์š”๊ธˆ์œผ๋กœ ์–ผ๋งˆ www.acmicpc.net ์ฝ”๋“œ import java.io.BufferedReader; import java.io.IOException; import java.i.. 2020. 3. 12.
[๋ฐฑ์ค€] 1911๋ฒˆ: ํ™๊ธธ ๋ณด์ˆ˜ํ•˜๊ธฐ(๊ทธ๋ฆฌ๋””) https://www.acmicpc.net/problem/1911 1911๋ฒˆ: ํ™๊ธธ ๋ณด์ˆ˜ํ•˜๊ธฐ ์–ด์ ฏ๋ฐค ๊ฒจ์šธ ์บ ํ”„ ์žฅ์†Œ์—์„œ ์›”๋“œ ๋ณธ์›๊นŒ์ง€ ์ด์–ด์ง€๋Š”, ํ™์œผ๋กœ ๋œ ๋น„๋ฐ€๊ธธ ์œ„์— ํญ์šฐ๊ฐ€ ๋‚ด๋ ค์„œ N (1 range) { range += L; nulpan ++; } } } System.out.println(nulpan); bf.close(); } } ํ’€์ด ์ผ๋‹จ ๊ทธ๋ฆฌ๋”” ๋ฌธ์ œ์—ฌ์„œ ํ•˜๋‚˜ํ•˜๋‚˜ ํƒ์š•์Šค๋Ÿฝ๊ฒŒ ์ ‘๊ทผํ• ๊ฑฐ๊ธฐ ๋•Œ๋ฌธ์—, ์ฃผ์–ด์ง„ ๋ฌผ ์›…๋ฉ์ด์˜ ์‹œ์ž‘์œ„์น˜, ๋์œ„์น˜๋ฅผ ์ •๋ ฌ์„ ํ•ด์•ผ๊ฒ ๋‹ค๋Š” ์ƒ๊ฐ์„ ํ–ˆ๋‹ค. ์ •๋ ฌ ์กฐ๊ฑด์€ ๋ฌผ ์›…๋ฉ์ด์˜ ์‹œ์ž‘ ์œ„์น˜๊ฐ€ ๊ฐ€์žฅ ์ž‘์€ ๊ฒƒ ๋ถ€ํ„ฐ, ๊ฐ™์œผ๋ฉด ๋์œ„์น˜๊ฐ€ ์ž‘์€๊ฒƒ๋ถ€ํ„ฐ ์ •๋ ฌํ–ˆ๋‹ค. Comparator ์ธํ„ฐํŽ˜์ด์Šค ์ฐธ๊ณ  ๊ทธ ํ›„, ํ•˜๋‚˜ํ•˜๋‚˜ ๋น„๊ตํ•ด๊ฐ€๋ฉฐ ๋„๋นค์ง€๋ฅผ ์„ค์น˜ํ•  ๊ฒƒ์ธ์ง€? ์„ค์น˜ํ•œ๋‹ค๋ฉด ๋ช‡๊ฐœ์„ค์น˜ํ•˜๋Š”์ง€ ํŒ๋‹จ์„ ํ•˜๋ฉด ๋˜๋Š”๋ฐ ์—ฌ๊ธฐ์„œ.. 2020. 3. 12.
[Codeforces] 1311A: Add Odd or Subtract Even https://codeforces.com/problemset/problem/1311/A Problem - 1311A - 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; tcb) ans = ((a-b) % 2 == 0) ? 1 : 2; else ans = ((b-a) % 2 == 0) ? 2 : 1; System.out.println(ans); } scan.close(); } } ํ’€์ด ๋ฌธ์ œ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค. a, b.. 2020. 3. 12.
[Codeforces] 1003A: Polycarp's Pockets https://codeforces.com/problemset/problem/1003/A Problem - 1003A - Codeforces codeforces.com ์ฝ”๋“œ import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); int[] arr = new int[n]; int[] value = new int[101]; for(int i=0; i 2020. 3. 11.
[๋ฐฑ์ค€] 11729๋ฒˆ: ํ•˜๋…ธ์ด ํƒ‘ ์ด๋™ ์ˆœ์„œ(์žฌ๊ท€, ๋ถ„ํ• ์ •๋ณต) https://www.acmicpc.net/problem/11729 11729๋ฒˆ: ํ•˜๋…ธ์ด ํƒ‘ ์ด๋™ ์ˆœ์„œ ์„ธ ๊ฐœ์˜ ์žฅ๋Œ€๊ฐ€ ์žˆ๊ณ  ์ฒซ ๋ฒˆ์งธ ์žฅ๋Œ€์—๋Š” ๋ฐ˜๊ฒฝ์ด ์„œ๋กœ ๋‹ค๋ฅธ n๊ฐœ์˜ ์›ํŒ์ด ์Œ“์—ฌ ์žˆ๋‹ค. ๊ฐ ์›ํŒ์€ ๋ฐ˜๊ฒฝ์ด ํฐ ์ˆœ์„œ๋Œ€๋กœ ์Œ“์—ฌ์žˆ๋‹ค. ์ด์ œ ์ˆ˜๋„์Šน๋“ค์ด ๋‹ค์Œ ๊ทœ์น™์— ๋”ฐ๋ผ ์ฒซ ๋ฒˆ์งธ ์žฅ๋Œ€์—์„œ ์„ธ ๋ฒˆ์งธ ์žฅ๋Œ€๋กœ ์˜ฎ๊ธฐ๋ ค ํ•œ๋‹ค. ํ•œ ๋ฒˆ์— ํ•œ ๊ฐœ์˜ ์›ํŒ๋งŒ์„ ๋‹ค๋ฅธ ํƒ‘์œผ๋กœ ์˜ฎ๊ธธ ์ˆ˜ ์žˆ๋‹ค. ์Œ“์•„ ๋†“์€ ์›ํŒ์€ ํ•ญ์ƒ ์œ„์˜ ๊ฒƒ์ด ์•„๋ž˜์˜ ๊ฒƒ๋ณด๋‹ค ์ž‘์•„์•ผ ํ•œ๋‹ค. ์ด ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•˜๋Š”๋ฐ ํ•„์š”ํ•œ ์ด๋™ ์ˆœ์„œ๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜๋ผ. ๋‹จ, ์ด๋™ ํšŸ์ˆ˜๋Š” ์ตœ์†Œ๊ฐ€ ๋˜์–ด์•ผ ํ•œ๋‹ค. ์•„๋ž˜ ๊ทธ๋ฆผ์€ ์›ํŒ์ด 5 www.acmicpc.net ์ฝ”๋“œ import java.util.Scanner; public class Main { static StringBuild.. 2020. 3. 11.
[Codeforces] 978B: File Name https://codeforces.com/problemset/problem/978/B Problem - 978B - Codeforces codeforces.com ์ฝ”๋“œ import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); String str = scan.next(); int delete = 0; // ๋ฌธ์ž์—ด์—์„œ "xxx"๊ฐ€ ์žˆ์„๋•Œ => delete ํ•œ๊ฐœ์”ฉ ์ฆ๊ฐ€. for(int i=0; i 2020. 3. 11.
๋ฐ˜์‘ํ˜•