์ „์ฒด ๊ธ€ 278

[BOJ/Step3] 2741 : N ์ฐ๊ธฐ (JAVA)

www.acmicpc.net/problem/2741 2741๋ฒˆ: N ์ฐ๊ธฐ ์ž์—ฐ์ˆ˜ N์ด ์ฃผ์–ด์กŒ์„ ๋•Œ, 1๋ถ€ํ„ฐ N๊นŒ์ง€ ํ•œ ์ค„์— ํ•˜๋‚˜์”ฉ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. www.acmicpc.net ๋ฌธ์ œ ์ž์—ฐ์ˆ˜ N์ด ์ฃผ์–ด์กŒ์„ ๋•Œ, 1๋ถ€ํ„ฐ N๊นŒ์ง€ ํ•œ ์ค„์— ํ•˜๋‚˜์”ฉ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. ์ž…๋ ฅ ์ฒซ์งธ ์ค„์— 100,000๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ž์—ฐ์ˆ˜ N์ด ์ฃผ์–ด์ง„๋‹ค. ์ถœ๋ ฅ ์ฒซ์งธ ์ค„๋ถ€ํ„ฐ N๋ฒˆ์งธ ์ค„ ๊นŒ์ง€ ์ฐจ๋ก€๋Œ€๋กœ ์ถœ๋ ฅํ•œ๋‹ค. ์˜ˆ์ œ ์ž…๋ ฅ 5 ์˜ˆ์ œ ์ถœ๋ ฅ 1 2 3 4 5 ํ’€์ด package Step3; import java.io.*; public class B2741 { public static void main(String[] args) throws IOException { BufferedReader br = new Buff..

[BOJ/Step3] 15552 : ๋น ๋ฅธ A+B (JAVA)

www.acmicpc.net/problem/15552 15552๋ฒˆ: ๋น ๋ฅธ A+B ์ฒซ ์ค„์— ํ…Œ์ŠคํŠธ์ผ€์ด์Šค์˜ ๊ฐœ์ˆ˜ T๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. T๋Š” ์ตœ๋Œ€ 1,000,000์ด๋‹ค. ๋‹ค์Œ T์ค„์—๋Š” ๊ฐ๊ฐ ๋‘ ์ •์ˆ˜ A์™€ B๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. A์™€ B๋Š” 1 ์ด์ƒ, 1,000 ์ดํ•˜์ด๋‹ค. www.acmicpc.net ๋ฌธ์ œ ๋ณธ๊ฒฉ์ ์œผ๋กœ for๋ฌธ ๋ฌธ์ œ๋ฅผ ํ’€๊ธฐ ์ „์— ์ฃผ์˜ํ•ด์•ผ ํ•  ์ ์ด ์žˆ๋‹ค. ์ž…์ถœ๋ ฅ ๋ฐฉ์‹์ด ๋Š๋ฆฌ๋ฉด ์—ฌ๋Ÿฌ ์ค„์„ ์ž…๋ ฅ๋ฐ›๊ฑฐ๋‚˜ ์ถœ๋ ฅํ•  ๋•Œ ์‹œ๊ฐ„์ดˆ๊ณผ๊ฐ€ ๋‚  ์ˆ˜ ์žˆ๋‹ค๋Š” ์ ์ด๋‹ค. C++์„ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๊ณ  cin/cout์„ ์‚ฌ์šฉํ•˜๊ณ ์ž ํ•œ๋‹ค๋ฉด, cin.tie(NULL)๊ณผ sync_with_stdio(false)๋ฅผ ๋‘˜ ๋‹ค ์ ์šฉํ•ด ์ฃผ๊ณ , endl ๋Œ€์‹  ๊ฐœํ–‰๋ฌธ์ž(\n)๋ฅผ ์“ฐ์ž. ๋‹จ, ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ๋” ์ด์ƒ scanf/printf/puts/getchar/putcha..

[JAVA] BufferedReader / BufferedWriter ํด๋ž˜์Šค

docs.oracle.com/en/java/javase/15/docs/api/java.base/java/io/BufferedReader.html BufferedReader (Java SE 15 & JDK 15) All Implemented Interfaces: Closeable, AutoCloseable, Readable Direct Known Subclasses: LineNumberReader public class BufferedReader extends Reader Reads text from a character-input stream, buffering characters so as to provide for the efficient reading of docs.oracle.com docs.or..

2021-01-06

์˜ค๋Š˜ ๋ช‡ ์—†๋Š” ๋ฌธ์ œํ’€์ด๋“ค์„ ๋…ธ์…˜์—์„œ ์˜ฎ๊ฒจ์™”๋‹ค. ์˜ค๋žœ๋งŒ์— ์ž๋ฐ”๋ฅผ ํ•˜๋Š”๋ฐ ์ž๋ฐ”๋„ ์–ด๋ ต๊ณ , ๊ฒจ์šฐ ๋ธ”๋กœ๊ทธ์ธ๋ฐ๋„ ๊ธ€ ์“ฐ๋Š”๊ฒŒ ์–ด๋ ต๋‹ค. ์ฑ…์„ 4๊ถŒ ์ƒ€๋‹ค. ์•„์ง ์ž๋ฐ”๋„ ํŒŒ์ด์ฌ๋„ ์ œ๋Œ€๋กœ ํ•˜๋Š”๊ฑด ์—†์ง€๋งŒ ์š•์‹ฌ์ด ์ƒ๊ฒจ์„œ ๊ทธ๋Ÿฐ๊ฐ€ ๋‹ค๋ถ„ํžˆ ์ถฉ๋™์ ์ธ ๊ตฌ๋งค์˜€๋‹ค. ๊ธฐ๋ณธ์ ์ธ ๋ถ€๋ถ„๋“ค์ด ์ข€ ์ต์ˆ™ํ•ด์ง€๋ฉด ๋ณธ๊ฒฉ์ ์œผ๋กœ ์ž๋ฃŒ๊ตฌ์กฐ๋ฅผ ๊ณต๋ถ€ํ•ด์„œ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ๋” ๋งŽ์ด ๋ฐฐ์šฐ๊ณ  ์‹ถ๋‹ค. ๊ทธ๋Ÿฌ๋ฉด ์ง€๊ธˆ๋ณด๋‹ค ๋ฌธ์ œํ’€์ด๊ฐ€ ๋” ์‰ฌ์›Œ์ง€๊ฒ ์ง€.. ์ฃผ๋ณ€์—์„œ ์ทจ์—… ์†Œ์‹์ด ์ž๊พธ ๋“ค๋ ค์˜จ๋‹ค. ๊ธ‰ํ•œ ๋งˆ์Œ์„ ๊ฐ–์ง€ ์•Š์œผ๋ ค๊ณ  ํ•˜์ง€๋งŒ ๋งˆ์Œ ํ•œ๊ตฌ์„์ด ์กฐ๊ธ‰ํ•ด์ง€๋Š”๊ฑด ์–ด์ฉ” ์ˆ˜ ์—†๋‚˜๋ณด๋‹ค. ๊ทธ๋ž˜๋„ ๋‚ด๊ฐ€ ๋” ์—ด์‹ฌํžˆ ํ•˜๋ฉด ๊ทธ๋งŒํผ ์ข‹์€ ๊ฒฐ๊ณผ๊ฐ€ ์˜ค๋ฆฌ๋ผ ๋ฏฟ๋Š”๋‹ค.

[BOJ/Step3] 8393 : ํ•ฉ (JAVA)

www.acmicpc.net/problem/8393 8393๋ฒˆ: ํ•ฉ n์ด ์ฃผ์–ด์กŒ์„ ๋•Œ, 1๋ถ€ํ„ฐ n๊นŒ์ง€ ํ•ฉ์„ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. www.acmicpc.net ๋ฌธ์ œ n์ด ์ฃผ์–ด์กŒ์„ ๋•Œ, 1๋ถ€ํ„ฐ n๊นŒ์ง€ ํ•ฉ์„ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. ์ž…๋ ฅ ์ฒซ์งธ ์ค„์— n (1 ≤ n ≤ 10,000)์ด ์ฃผ์–ด์ง„๋‹ค. ์ถœ๋ ฅ 1๋ถ€ํ„ฐ n๊นŒ์ง€ ํ•ฉ์„ ์ถœ๋ ฅํ•œ๋‹ค. ์˜ˆ์ œ ์ž…๋ ฅ 1 3 ์˜ˆ์ œ ์ถœ๋ ฅ 1 6 ํ’€์ด import java.util.Scanner; public class B8393 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int total = 0; for(int i = 1; i < n+1;..

[JAVA] getNumericValue() ๋ฉ”์†Œ๋“œ

docs.oracle.com/en/java/javase/15/docs/api/java.base/java/lang/Character.html#getNumericValue(int) Character (Java SE 15 & JDK 15) All Implemented Interfaces: Serializable, Comparable , Constable public final class Character extends Object implements Serializable, Comparable , Constable The Character class wraps a value of the primitive type char in an object. An object of class Chara docs.oracl..

[JAVA] charAt() ๋ฉ”์†Œ๋“œ

docs.oracle.com/en/java/javase/15/docs/api/java.base/java/lang/String.html#charAt(int) String (Java SE 15 & JDK 15) All Implemented Interfaces: Serializable, CharSequence, Comparable , Constable, ConstantDesc public final class String extends Object implements Serializable, Comparable , CharSequence, Constable, ConstantDesc The String class represents character strings. docs.oracle.com java.lang..

[BOJ/Step3] 10950 : A+B - 3 (JAVA)

www.acmicpc.net/problem/10950 10950๋ฒˆ: A+B - 3 ๋‘ ์ •์ˆ˜ A์™€ B๋ฅผ ์ž…๋ ฅ๋ฐ›์€ ๋‹ค์Œ, A+B๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. www.acmicpc.net ๋ฌธ์ œ ๋‘ ์ •์ˆ˜ A์™€ B๋ฅผ ์ž…๋ ฅ๋ฐ›์€ ๋‹ค์Œ, A+B๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. ์ž…๋ ฅ ์ฒซ์งธ ์ค„์— ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค์˜ ๊ฐœ์ˆ˜ T๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ๊ฐ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค๋Š” ํ•œ ์ค„๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ์œผ๋ฉฐ, ๊ฐ ์ค„์— A์™€ B๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. (0 < A, B < 10) ์ถœ๋ ฅ ๊ฐ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค๋งˆ๋‹ค A+B๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค. ์˜ˆ์ œ ์ž…๋ ฅ 1 5 1 1 2 3 3 4 9 8 5 2 ์˜ˆ์ œ ์ถœ๋ ฅ 1 2 5 7 17 7 ํ’€์ด import java.util.Scanner; public class B10950 { public static void main(String[]..

[BOJ/Step3] 2739 : ๊ตฌ๊ตฌ๋‹จ (JAVA)

www.acmicpc.net/problem/2739 2739๋ฒˆ: ๊ตฌ๊ตฌ๋‹จ N์„ ์ž…๋ ฅ๋ฐ›์€ ๋’ค, ๊ตฌ๊ตฌ๋‹จ N๋‹จ์„ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. ์ถœ๋ ฅ ํ˜•์‹์— ๋งž์ถฐ์„œ ์ถœ๋ ฅํ•˜๋ฉด ๋œ๋‹ค. www.acmicpc.net ๋ฌธ์ œ N์„ ์ž…๋ ฅ๋ฐ›์€ ๋’ค, ๊ตฌ๊ตฌ๋‹จ N๋‹จ์„ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. ์ถœ๋ ฅ ํ˜•์‹์— ๋งž์ถฐ์„œ ์ถœ๋ ฅํ•˜๋ฉด ๋œ๋‹ค. ์ž…๋ ฅ ์ฒซ์งธ ์ค„์— N์ด ์ฃผ์–ด์ง„๋‹ค. N์€ 1๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ , 9๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™๋‹ค. ์ถœ๋ ฅ ์ถœ๋ ฅํ˜•์‹๊ณผ ๊ฐ™๊ฒŒ N1๋ถ€ํ„ฐ N9๊นŒ์ง€ ์ถœ๋ ฅํ•œ๋‹ค. ์˜ˆ์ œ ์ž…๋ ฅ 1 2 ์˜ˆ์ œ ์ถœ๋ ฅ 1 2 * 1 = 2 2 * 2 = 4 2 * 3 = 6 2 * 4 = 8 2 * 5 = 10 2 * 6 = 12 2 * 7 = 14 2 * 8 = 16 2 * 9 = 18 ํ’€์ด import java.util.Scanner; public cla..

[BOJ/Step2] 2884 : ์•Œ๋žŒ ์‹œ๊ณ„ (JAVA)

www.acmicpc.net/problem/2884 2884๋ฒˆ: ์•Œ๋žŒ ์‹œ๊ณ„ ์ƒ๊ทผ์ด๋Š” ๋งค์ผ ์•„์นจ ์•Œ๋žŒ์„ ๋“ฃ๊ณ  ์ผ์–ด๋‚œ๋‹ค. ์•Œ๋žŒ์„ ๋“ฃ๊ณ  ๋ฐ”๋กœ ์ผ์–ด๋‚˜๋ฉด ๋‹คํ–‰์ด๊ฒ ์ง€๋งŒ, ํ•ญ์ƒ ์กฐ๊ธˆ๋งŒ ๋” ์ž๋ ค๋Š” ๋งˆ์Œ ๋•Œ๋ฌธ์— ๋งค์ผ ํ•™๊ต๋ฅผ ์ง€๊ฐํ•˜๊ณ  ์žˆ๋‹ค. ์ƒ๊ทผ์ด๋Š” ๋ชจ๋“  ๋ฐฉ๋ฒ•์„ ๋™์›ํ•ด๋ณด์•˜์ง€๋งŒ, www.acmicpc.net ๋ฌธ์ œ ์ƒ๊ทผ์ด๋Š” ๋งค์ผ ์•„์นจ ์•Œ๋žŒ์„ ๋“ฃ๊ณ  ์ผ์–ด๋‚œ๋‹ค. ์•Œ๋žŒ์„ ๋“ฃ๊ณ  ๋ฐ”๋กœ ์ผ์–ด๋‚˜๋ฉด ๋‹คํ–‰์ด๊ฒ ์ง€๋งŒ, ํ•ญ์ƒ ์กฐ๊ธˆ๋งŒ ๋” ์ž๋ ค๋Š” ๋งˆ์Œ ๋•Œ๋ฌธ์— ๋งค์ผ ํ•™๊ต๋ฅผ ์ง€๊ฐํ•˜๊ณ  ์žˆ๋‹ค. ์ƒ๊ทผ์ด๋Š” ๋ชจ๋“  ๋ฐฉ๋ฒ•์„ ๋™์›ํ•ด๋ณด์•˜์ง€๋งŒ, ์กฐ๊ธˆ๋งŒ ๋” ์ž๋ ค๋Š” ๋งˆ์Œ์€ ๊ทธ ์–ด๋–ค ๊ฒƒ๋„ ์—†์•จ ์ˆ˜๊ฐ€ ์—†์—ˆ๋‹ค. ์ด๋Ÿฐ ์ƒ๊ทผ์ด๋ฅผ ๋ถˆ์Œํ•˜๊ฒŒ ๋ณด๋˜, ์ฐฝ์˜์ด๋Š” ์ž์‹ ์ด ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์ถ”์ฒœํ•ด ์ฃผ์—ˆ๋‹ค. ๋ฐ”๋กœ "45๋ถ„ ์ผ์ฐ ์•Œ๋žŒ ์„ค์ •ํ•˜๊ธฐ"์ด๋‹ค. ์ด ๋ฐฉ๋ฒ•์€ ๋‹จ์ˆœํ•˜๋‹ค. ์›๋ž˜ ์„ค์ •๋˜์–ด ์žˆ๋Š” ์•Œ๋žŒ์„ 45..