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

Algorithm242

[Codeforces] 1095A: Repeating Cipher https://codeforces.com/problemset/problem/1095/A Problem - 1095A - 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(); String result = ""; int index = 0; for(int i=0; i= str.length()) break; result += str.charAt(index); index += (i+1); } System... 2020. 3. 9.
[Codeforces] 1077A: Frog Jumping https://codeforces.com/problemset/problem/1077/A Problem - 1077A - 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 2020. 3. 8.
ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค[Java] - ์˜ˆ์‚ฐ https://programmers.co.kr/learn/courses/30/lessons/12982 ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ์˜ˆ์‚ฐ | ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค S์‚ฌ์—์„œ๋Š” ๊ฐ ๋ถ€์„œ์— ํ•„์š”ํ•œ ๋ฌผํ’ˆ์„ ์ง€์›ํ•ด ์ฃผ๊ธฐ ์œ„ํ•ด ๋ถ€์„œ๋ณ„๋กœ ๋ฌผํ’ˆ์„ ๊ตฌ๋งคํ•˜๋Š”๋ฐ ํ•„์š”ํ•œ ๊ธˆ์•ก์„ ์กฐ์‚ฌํ–ˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜, ์ „์ฒด ์˜ˆ์‚ฐ์ด ์ •ํ•ด์ ธ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ๋ชจ๋“  ๋ถ€์„œ์˜ ๋ฌผํ’ˆ์„ ๊ตฌ๋งคํ•ด ์ค„ ์ˆ˜๋Š” ์—†์Šต๋‹ˆ๋‹ค. ๊ทธ๋ž˜์„œ ์ตœ๋Œ€ํ•œ ๋งŽ์€ ๋ถ€์„œ์˜ ๋ฌผํ’ˆ์„ ๊ตฌ๋งคํ•ด ์ค„ ์ˆ˜ ์žˆ๋„๋ก ํ•˜๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ๋ฌผํ’ˆ์„ ๊ตฌ๋งคํ•ด ์ค„ ๋•Œ๋Š” ๊ฐ ๋ถ€์„œ๊ฐ€ ์‹ ์ฒญํ•œ ๊ธˆ์•ก๋งŒํผ์„ ๋ชจ๋‘ ์ง€์›ํ•ด ์ค˜์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด 1,000์›์„ ์‹ ์ฒญํ•œ ๋ถ€์„œ์—๋Š” ์ •ํ™•ํžˆ 1,000์›์„ ์ง€์›ํ•ด์•ผ ํ•˜๋ฉฐ, 1,000์›๋ณด๋‹ค ์ ์€ ๊ธˆ์•ก์„ ์ง€์› programmers.co.kr ์ฝ”๋“œ import java.util.*; class Solution { pub.. 2020. 3. 8.
[Codeforces] 1285A: Mezo Playing Zoma https://codeforces.com/problemset/problem/1285/A Problem - 1285A - Codeforces codeforces.com ์ฝ”๋“œ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(bf.readLine()); String str = b.. 2020. 3. 8.
ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค[Java] - ์†Œ์ˆ˜ ์ฐพ๊ธฐ https://programmers.co.kr/learn/courses/30/lessons/12921 ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ์†Œ์ˆ˜ ์ฐพ๊ธฐ | ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค 1๋ถ€ํ„ฐ ์ž…๋ ฅ๋ฐ›์€ ์ˆซ์ž n ์‚ฌ์ด์— ์žˆ๋Š” ์†Œ์ˆ˜์˜ ๊ฐœ์ˆ˜๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” ํ•จ์ˆ˜, solution์„ ๋งŒ๋“ค์–ด ๋ณด์„ธ์š”. ์†Œ์ˆ˜๋Š” 1๊ณผ ์ž๊ธฐ ์ž์‹ ์œผ๋กœ๋งŒ ๋‚˜๋ˆ„์–ด์ง€๋Š” ์ˆ˜๋ฅผ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. (1์€ ์†Œ์ˆ˜๊ฐ€ ์•„๋‹™๋‹ˆ๋‹ค.) ์ œํ•œ ์กฐ๊ฑด n์€ 2์ด์ƒ 1000000์ดํ•˜์˜ ์ž์—ฐ์ˆ˜์ž…๋‹ˆ๋‹ค. ์ž…์ถœ๋ ฅ ์˜ˆ n result 10 4 5 3 ์ž…์ถœ๋ ฅ ์˜ˆ ์„ค๋ช… ์ž…์ถœ๋ ฅ ์˜ˆ #1 1๋ถ€ํ„ฐ 10 ์‚ฌ์ด์˜ ์†Œ์ˆ˜๋Š” [2,3,5,7] 4๊ฐœ๊ฐ€ ์กด์žฌํ•˜๋ฏ€๋กœ 4๋ฅผ ๋ฐ˜ํ™˜ ์ž…์ถœ๋ ฅ ์˜ˆ #2 1๋ถ€ํ„ฐ 5 ์‚ฌ์ด์˜ ์†Œ์ˆ˜๋Š” [2,3,5] 3๊ฐœ๊ฐ€ ์กด์žฌ programmers.co.kr ์ฝ”๋“œ class Solution { public int solution(.. 2020. 3. 7.
ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค[Java] - ๋ฌธ์ž์—ด ๋‹ค๋ฃจ๊ธฐ ๊ธฐ๋ณธ https://programmers.co.kr/learn/courses/30/lessons/12918 ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ๋ฌธ์ž์—ด ๋‹ค๋ฃจ๊ธฐ ๊ธฐ๋ณธ | ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ๋ฌธ์ž์—ด s์˜ ๊ธธ์ด๊ฐ€ 4 ํ˜น์€ 6์ด๊ณ , ์ˆซ์ž๋กœ๋งŒ ๊ตฌ์„ฑ๋ผ์žˆ๋Š”์ง€ ํ™•์ธํ•ด์ฃผ๋Š” ํ•จ์ˆ˜, solution์„ ์™„์„ฑํ•˜์„ธ์š”. ์˜ˆ๋ฅผ ๋“ค์–ด s๊ฐ€ a234์ด๋ฉด False๋ฅผ ๋ฆฌํ„ดํ•˜๊ณ  1234๋ผ๋ฉด True๋ฅผ ๋ฆฌํ„ดํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค. ์ œํ•œ ์‚ฌํ•ญ s๋Š” ๊ธธ์ด 1 ์ด์ƒ, ๊ธธ์ด 8 ์ดํ•˜์ธ ๋ฌธ์ž์—ด์ž…๋‹ˆ๋‹ค. ์ž…์ถœ๋ ฅ ์˜ˆ s return a234 false 1234 true programmers.co.kr ์ฝ”๋“œ class Solution { public boolean solution(String s) { boolean answer = true; // ๊ธธ์ด๊ฐ€ 4๋‚˜ 6์ด ์•„๋‹Œ๊ฒฝ์šฐ => false if(s.. 2020. 3. 7.
[๋ฐฑ์ค€] 5052๋ฒˆ: ์ „ํ™”๋ฒˆํ˜ธ ๋ชฉ๋ก https://www.acmicpc.net/problem/5052 5052๋ฒˆ: ์ „ํ™”๋ฒˆํ˜ธ ๋ชฉ๋ก ๋ฌธ์ œ ์ „ํ™”๋ฒˆํ˜ธ ๋ชฉ๋ก์ด ์ฃผ์–ด์ง„๋‹ค. ์ด๋•Œ, ์ด ๋ชฉ๋ก์ด ์ผ๊ด€์„ฑ์ด ์žˆ๋Š”์ง€ ์—†๋Š”์ง€๋ฅผ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. ์ „ํ™”๋ฒˆํ˜ธ ๋ชฉ๋ก์ด ์ผ๊ด€์„ฑ์„ ์œ ์ง€ํ•˜๋ ค๋ฉด, ํ•œ ๋ฒˆํ˜ธ๊ฐ€ ๋‹ค๋ฅธ ๋ฒˆํ˜ธ์˜ ์ ‘๋‘์–ด์ธ ๊ฒฝ์šฐ๊ฐ€ ์—†์–ด์•ผ ํ•œ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ์ „ํ™”๋ฒˆํ˜ธ ๋ชฉ๋ก์ด ์•„๋ž˜์™€ ๊ฐ™์€ ๊ฒฝ์šฐ๋ฅผ ์ƒ๊ฐํ•ด๋ณด์ž ๊ธด๊ธ‰์ „ํ™”: 911 ์ƒ๊ทผ: 97 625 999 ์„ ์˜: 91 12 54 26 ์ด ๊ฒฝ์šฐ์— ์„ ์˜์ด์—๊ฒŒ ์ „ํ™”๋ฅผ ๊ฑธ ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•์ด ์—†๋‹ค. ์ „ํ™”๊ธฐ๋ฅผ ๋“ค๊ณ  ์„ ์˜์ด ๋ฒˆํ˜ธ์˜ ์ฒ˜์Œ ์„ธ ์ž๋ฆฌ๋ฅผ ๋ˆ„๋ฅด๋Š” ์ˆœ๊ฐ„ ๋ฐ”๋กœ ๊ธด๊ธ‰์ „ํ™”๊ฐ€ www.acmicpc.net ์ฝ”๋“œ import java.io.BufferedReader; import java.io.IOException; import java... 2020. 3. 7.
[Codeforces] 431A: Black Square https://codeforces.com/problemset/problem/431/A Problem - 431A - Codeforces codeforces.com ์ฝ”๋“œ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws IOException { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = ne.. 2020. 3. 7.
ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค[Java] - ์œ„์žฅ(ํ•ด์‹œ) https://programmers.co.kr/learn/courses/30/lessons/42578 ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ์œ„์žฅ | ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค programmers.co.kr ์ฝ”๋“œ import java.util.*; class Solution { public int solution(String[][] clothes) { HashMap map = new HashMap(); int answer = 1; for(int i=0; i 2020. 3. 6.
[๋ฐฑ์ค€] 1062๋ฒˆ: ๊ฐ€๋ฅด์นจ(์™„์ „ ํƒ์ƒ‰, ๋ฐฑํŠธ๋ž˜ํ‚น) https://www.acmicpc.net/problem/1062 1062๋ฒˆ: ๊ฐ€๋ฅด์นจ ์ฒซ์งธ ์ค„์— ๋‹จ์–ด์˜ ๊ฐœ์ˆ˜ N๊ณผ K๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. N์€ 50๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ž์—ฐ์ˆ˜์ด๊ณ , K๋Š” 26๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ž์—ฐ์ˆ˜ ๋˜๋Š” 0์ด๋‹ค. ๋‘˜์งธ ์ค„๋ถ€ํ„ฐ N๊ฐœ์˜ ์ค„์— ๋‚จ๊ทน ์–ธ์–ด์˜ ๋‹จ์–ด๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ๋‹จ์–ด๋Š” ์˜์–ด ์†Œ๋ฌธ์ž๋กœ๋งŒ ์ด๋ฃจ์–ด์ ธ ์žˆ๊ณ , ๊ธธ์ด๊ฐ€ 8๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ , 15๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™๋‹ค. ๋ชจ๋“  ๋‹จ์–ด๋Š” ์ค‘๋ณต๋˜์ง€ ์•Š๋Š”๋‹ค. www.acmicpc.net ์ฝ”๋“œ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { static int .. 2020. 3. 6.
๋ฐ˜์‘ํ˜•