๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

SWEA12

[SWEA] 1926. ๊ฐ„๋‹จํ•œ 369๊ฒŒ์ž„ 1926. ๊ฐ„๋‹จํ•œ 369๊ฒŒ์ž„ - D2 N์„ ์ž…๋ ฅ๋ฐ›๊ณ  1๋ถ€ํ„ฐ N๊นŒ์ง€ ์ถœ๋ ฅํ•˜๋Š” ๋ฐ, 3,6,9๋ฅผ ํฌํ•จํ•œ ๊ฒฝ์šฐ ์ด ์ˆซ์ž๋“ค์„ "-"๋ฌธ์ž๋กœ ๋Œ€์ฒดํ•˜๋Š” ๋ฌธ์ œ์ด๋‹ค. ์šฐ์„ , N์„ ์ž…๋ ฅ๋ฐ›๊ณ  for๋ฌธ์„ ์ด์šฉํ•ด N๋งŒํผ 1๋ถ€ํ„ฐ ์ถœ๋ ฅํ•ด๋‚˜๊ฐ€๋Š”๋ฐ, ํŠน์ •์กฐ๊ฑด์ผ ๊ฒฝ์šฐ "-"๋ฅผ ์ถœ๋ ฅํ•  ์ˆ˜ ์žˆ๋„๋ก ํ–ˆ๋‹ค. 1. N์„ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค. 2. 1๋ถ€ํ„ฐ N๊นŒ์ง€ ์ฆ๊ฐ€ํ•˜๋Š” i๋ฅผ ๋ฌธ์ž์—ด s๋กœ ์น˜ํ™˜ํ•˜๊ณ , 3. 3,6,9๋ฅผ ํฌํ•จํ•˜์ง€ ์•Š์€ ๊ฒฝ์šฐ i๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค. 4. 3,6,9๋ฅผ ํฌํ•จํ•œ ๊ฒฝ์šฐ i์˜ ์ž๋ฆฟ์ˆ˜๋งŒํผ ๋ฐ˜๋ณตํ•˜๋ฉฐ ๋ฌธ์ž์—ด s๋‚ด์—์„œ charAt์„ ์ด์šฉํ•ด, 3, 6, 9๋ฅผ ํฌํ•จํ•œ ๊ฒฝ์šฐ "-"๋ฌธ์ž๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค. import java.util.Scanner; import java.io.FileInputStream; class Solution { public static v.. 2022. 5. 29.
[SWEA] 1859. ๋ฐฑ๋งŒ ์žฅ์ž ํ”„๋กœ์ ํŠธ 1859. ๋ฐฑ๋งŒ ์žฅ์ž ํ”„๋กœ์ ํŠธ - D2 ์ด์ œ D2 ๋ ˆ๋ฒจ ๋ฌธ์ œ์ด๋‹ค. ๋งจ ์ฒซ๋ฒˆ์งธ ์ˆ˜ T๋Š” ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค์˜ ์ˆ˜์ด๋‹ค. ๊ฐ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค์˜ ์ฒซ์ค„์—๋Š” N์ผ์„ ์ž…๋ ฅ ๋ฐ›๊ณ , ๊ทธ ๋ฐ‘์ค„์—๋Š” ๊ฐ ๋‚ ์˜ ๋งค๋งค๊ฐ€๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” N๊ฐœ์˜ ์ž์—ฐ์ˆ˜(int [] num)๊ฐ€ ์ž…๋ ฅ๋œ๋‹ค. profit์€ ์ถœ๋ ฅํ•  ๋ˆ„์  ์ด์ต์„ ์ €์žฅํ•œ๋‹ค. (N์˜ ๋ฒ”์œ„๊ฐ€ 2 ≤ N ≤ 1,000,000 ์ด๊ธฐ ๋•Œ๋ฌธ์— longํƒ€์ž…์œผ๋กœ ์„ ์–ธํ–ˆ๋‹ค.) max๋Š” ๋งค๋งค๊ฐ€์˜ ์ตœ๋Œ€๊ฐ’์„ ์ €์žฅํ•œ๋‹ค. for๋ฌธ์€ ๋’ค์—์„œ ๋ถ€ํ„ฐ ๊ฐ์†Œ์‹œํ‚ค๋ฉฐ ๋ฐ˜๋ณตํ•˜๋Š”๋ฐ, ์ตœ๋Œ€๊ฐ’์ด num[i]๋ณด๋‹ค ์ ์œผ๋ฉด ๊ตฌ๋งค๋ฅผ ํ•˜์ง€ ์•Š๋Š”๋‹ค ์ƒ๊ฐํ•˜๊ณ  max = num[i]๋กœ ํ•œ๋‹ค. ์ตœ๋Œ€๊ฐ’์ด ์•„๋‹Œ ๊ฒฝ์šฐ์—๋Š” ์ด์ต์— ํ˜„์žฌ์˜ ๋งˆ์ง„(max-num[i])์„ ๊ตฌํ•œ๋‹ค. import java.util.Scanner; import java.io.File.. 2022. 5. 28.
[SWEA] 1545. ๊ฑฐ๊พธ๋กœ ์ถœ๋ ฅํ•ด ๋ณด์•„์š” 1545. ๊ฑฐ๊พธ๋กœ ์ถœ๋ ฅํ•ด ๋ณด์•„์š” - D1 D1๋ ˆ๋ฒจ ๋งˆ์ง€๋ง‰ ๋ฌธ์ œ์ธ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค..! ์ž…๋ ฅ๋œ ์ˆซ์ž N์„ N๋ถ€ํ„ฐ -1ํ•˜๋ฉฐ ๊ฑฐ๊พธ๋กœ ์ถœ๋ ฅํ•ด, 0๊นŒ์ง€ ์ถœ๋ ฅํ•ด๋‚ด๋Š” ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค. for๋ฌธ์„ ์ด์šฉํ•˜๋Š”๋ฐ i๋ฅผ N๋ถ€ํ„ฐ ํ•˜๊ณ  i--ํ•˜๋ฉด์„œ i๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ๊ตฌํ˜„ํ–ˆ์Šต๋‹ˆ๋‹ค. import java.util.Scanner; import java.io.FileInputStream; class Solution { public static void main(String args[]) throws Exception { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); for(int i = N; i >= 0; i--) { System.out.print(i+" "); } } } ๋ ๐Ÿง 2022. 5. 24.
[SWEA] 1936. 1๋Œ€1 ๊ฐ€์œ„๋ฐ”์œ„๋ณด 1936. 1๋Œ€1 ๊ฐ€์œ„๋ฐ”์œ„๋ณด - D1 ๋น„๊ธฐ๋Š” ๊ฒฝ์šฐ๊ฐ€ ์—†๋Š” ๊ฐ€์œ„๋ฐ”์œ„๋ณด์—์„œ A์™€ B ์ค‘ ์ด๊ธฐ๋Š” ์‚ฌ๋žŒ์„ ๊ตฌํ•˜๋Š” ๋ฌธ์ œ์ด๋‹ค. ๊ฒฝ์šฐ์˜ ์ˆ˜๊ฐ€ ๋งŽ์ง€ ์•Š์•„์„œ ๊ทธ๋ƒฅ result์— B๋ฅผ ๋„ฃ์–ด ์ดˆ๊ธฐํ™”ํ•˜๊ณ  A๊ฐ€ ์ด๊ธธ ์กฐ๊ฑด์ผ ๊ฒฝ์šฐ์— result์— A๋ฅผ ๋Œ€์ž…ํ•˜๋„๋ก ํ–ˆ๋‹ค. ๊ฐ€์œ„๋Š” 1, ๋ฐ”์œ„๋Š” 2, ๋ณด๋Š” 3์ผ ๋•Œ A๊ฐ€ ๊ฐ€์œ„๋ฐ”์œ„๋ณด์—์„œ ์ด๊ธธ ์ˆ˜ ์žˆ๋Š” ๊ฒฝ์šฐ๋Š” A == 1 ์ผ๋•Œ B == 3 -> A-B==-2 A == 2 ์ผ๋•Œ B == 1 -> A-B==1 A == 3 ์ผ๋•Œ B == 2 -> A-B==1 ๊ฒฝ์šฐ์ด๋‹ค. ์ด๋•Œ ์กฐ๊ฑด์€ ๊ทธ๋ƒฅ A-B == -2 || A-B==1์„ ์ด์šฉํ–ˆ๋‹ค. B๋„ ์กฐ๊ฑด์œผ๋กœ ํ’€ ์ˆ˜๋Š” ์žˆ๋Š”๋ฐ ์ด ๋•Œ ์œ„ ์ฒ˜๋Ÿผ ๊ฐ„๋‹จํžˆ ๋‘ ์ˆ˜์˜ ์ฐจ๋ฅผ ์ด์šฉํ•  ๊ฒฝ์šฐ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค. B๊ฐ€ ์ด๊ธฐ๋Š” ์กฐ๊ฑด์€ A == 1 ์ผ๋•Œ B == 2 -> A-B==-1.. 2022. 5. 20.
[SWEA] 1933. ๊ฐ„๋‹จํ•œ N์˜ ์•ฝ์ˆ˜ 1933. ๊ฐ„๋‹จํ•œ N์˜ ์•ฝ์ˆ˜ - D1 ์•ฝ์ˆ˜์˜ ๊ฐœ๋…์„ ์ด์šฉํ•œ๋‹ค. ์•ฝ์ˆ˜๋Š” N์„ ์–ด๋–ค ์ˆ˜๋กœ ๋‚˜๋ˆด์„ ๋•Œ ๋‚˜๋จธ์ง€๊ฐ€ 0์ธ ๊ฒƒ์ด๋‹ค. import java.util.Scanner; import java.io.FileInputStream; class Solution { public static void main(String args[]) throws Exception { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); for(int i = 1; i 2022. 5. 19.
[SWEA] 1938. ์•„์ฃผ ๊ฐ„๋‹จํ•œ ๊ณ„์‚ฐ๊ธฐ 1938. ์•„์ฃผ ๊ฐ„๋‹จํ•œ ๊ณ„์‚ฐ๊ธฐ - D1 ๋‘ ์ˆซ์ž๋ฅผ ๋ฐ›์•„ ์‚ฌ์น™์—ฐ์‚ฐ(+, -, *, /)์„ ์ˆœ์„œ๋Œ€๋กœ ํ•˜๊ณ  ์ถœ๋ ฅํ•˜๋Š” ๋ฌธ์ œ์ด๋‹ค. num1, num2๋ฅผ ์ž…๋ ฅ๋ฐ›๊ณ  +, -, *, / ์ˆœ์„œ๋Œ€๋กœ ์—ฐ์‚ฐํ•œ ๊ฐ’์„ ์ถœ๋ ฅํ•˜๋„๋ก ํ–ˆ๋‹ค. import java.util.Scanner; import java.io.FileInputStream; class Solution { public static void main(String args[]) throws Exception { Scanner sc = new Scanner(System.in); int num1 = sc.nextInt(); int num2 = sc.nextInt(); System.out.println(num1+num2); System.out.println(num1-num2).. 2022. 5. 18.
[SWEA] 2025. N์ค„ ๋ง์…ˆ 2025. N์ค„ ๋ง์…ˆ - D1 ์ฃผ์–ด์ง„ ์ˆซ์ž N๊นŒ์ง€ 1๋ถ€ํ„ฐ ๋”ํ•œ ๊ฐ’์„ ์ถœ๋ ฅํ•˜๋Š” ๋ฌธ์ œ์ด๋‹ค. 1๋ถ€ํ„ฐ N๊นŒ์ง€ ๋”ํ•œ ํ•ฉ์€ N(N+1)/2 ๋ผ๋Š” ๊ณต์‹์„ ์ด์šฉํ•œ๋‹ค. (์ค‘ํ•™๊ต ๋•Œ ๋ฐฐ์› ๋˜ ๊ณต์‹์ธ ๊ฒƒ ๊ฐ™๋‹ค..?) import java.util.Scanner; import java.io.FileInputStream; class Solution { public static void main(String args[]) throws Exception { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); System.out.println(N*(N+1)/2); } } ๋ ๐Ÿง 2022. 5. 18.
[SWEA] 2027. ๋Œ€๊ฐ์„  ์ถœ๋ ฅํ•˜๊ธฐ 2027. ๋Œ€๊ฐ์„  ์ถœ๋ ฅํ•˜๊ธฐ - D1 ๊ทธ๋ƒฅ ์ถœ๋ ฅํ•˜๋ ค๋‹ค๊ฐ€ ๋ฐ˜๋ณต๋ฌธ ์—ฐ์Šตํ•˜๋ผ๋Š” ๊ฑด๊ฐ€ ์‹ถ์–ด์„œ ๋ฐ˜๋ณต๋ฌธ์„ ์ด์šฉํ–ˆ๋‹ค. i์™€ j๊ฐ€ ๊ฐ™์œผ๋ฉด #์„ ์ถœ๋ ฅํ•˜๊ณ  ์•„๋‹ ๊ฒฝ์šฐ +๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค. (ํ•™๊ต ๋‹ค๋‹ ๋•Œ ๋ณ„์ฐ๊ธฐ ์—ฐ์Šตํ•˜๋˜๊ฑฐ ์ƒ๊ฐ๋‚œใ„ทใ…..) import java.util.Scanner; import java.io.FileInputStream; class Solution { public static void main(String args[]) throws Exception { for(int i = 0; i < 5; i++) { for(int j = 0; j < 5; j++){ if(i==j) System.out.print("#"); else System.out.print("+"); } System.out.println(); } } }.. 2022. 5. 18.
[SWEA] 2043. ์„œ๋ž์˜ ๋น„๋ฐ€๋ฒˆํ˜ธ 2043. ์„œ๋ž์˜ ๋น„๋ฐ€๋ฒˆํ˜ธ - D1 K ์ˆ˜๋ถ€ํ„ฐ 1์”ฉ ์ฆ๊ฐ€ํ•ด๋ณด๋ฉฐ password๋ฅผ ๋งž์ถ”๋Š” ๋ฌธ์ œ์ด๋‹ค. ๋”ฐ๋ผ์„œ ์ž…๋ ฅ๋ฐ›์€ password์—์„œ K๋งŒํผ ๋นผ์ฃผ๊ณ  1์„ ๋”ํ•œ๋‹ค. import java.util.Scanner; import java.io.FileInputStream; class Solution { public static void main(String args[]) throws Exception { Scanner sc = new Scanner(System.in); int password =sc.nextInt(); int K = sc.nextInt(); System.out.println(password - K + 1); } } ๋ ๐Ÿง 2022. 5. 18.
[SWEA] 2046. ์Šคํƒฌํ”„ ์ฐ๊ธฐ 2046. ์Šคํƒฌํ”„ ์ฐ๊ธฐ - D1 ์ž…๋ ฅ๋ฐ›์€ ์ˆ˜๋งŒํผ for๋ฌธ์„ ๋Œ๋ ค #์„ ์ถœ๋ ฅํ•ด์ค€๋‹ค. System.out.println() ์œผ๋กœ ํ•˜๋ฉด ์ค„๋ฐ”๊ฟˆ ๋˜๋‹ˆ๊นŒ System.out.print() ์ด์šฉํ•˜๊ธฐ import java.util.Scanner; import java.io.FileInputStream; class Solution { public static void main(String args[]) throws Exception { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); for(int test_case = 1; test_case 2022. 5. 18.