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

Algorithm/๋ฐฑ์ค€ ์•Œ๊ณ ๋ฆฌ์ฆ˜42

[๋ฐฑ์ค€ ์•Œ๊ณ ๋ฆฌ์ฆ˜] 2750๋ฒˆ - ์ˆ˜ ์ •๋ ฌํ•˜๊ธฐ ๋ฌธ์ œ ) N๊ฐœ์˜ ์ˆ˜๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ, ์ด๋ฅผ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. ์ž…๋ ฅ ์ถœ๋ ฅ 5 5 2 3 4 1 1 2 3 4 5 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); // ์ž…๋ ฅ๋ฐ›์„ ๋ฐฐ์—ด ์ˆ˜ int[] arr = new int[n]; // ๋ฐฐ์—ด for (int i = 0; i < n; i++) { // ๋ฐฐ์—ด ์ˆ˜ ์ž…๋ ฅ arr[i] = sc.nextInt(); } int num = 0; // ๋ฒ„๋ธ” ์ •๋ ฌ for (int i = 0; i < arr.length; i++) { for (i.. 2021. 2. 2.
[๋ฐฑ์ค€ ์•Œ๊ณ ๋ฆฌ์ฆ˜] 11720๋ฒˆ - ์ˆซ์ž์˜ ํ•ฉ 8. ๋ฌธ์ž์—ด - ์ˆซ์ž์˜ ํ•ฉ ๋ฌธ์ œ ) N๊ฐœ์˜ ์ˆซ์ž๊ฐ€ ๊ณต๋ฐฑ ์—†์ด ์“ฐ์—ฌ์žˆ๋‹ค. ์ด ์ˆซ์ž๋ฅผ ๋ชจ๋‘ ํ•ฉํ•ด์„œ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. ์ž…๋ ฅ ์ถœ๋ ฅ 1 1 1 ์ž…๋ ฅ ์ถœ๋ ฅ 5 54321 15 ์ž…๋ ฅ ์ถœ๋ ฅ 25 7000000000000000000000000 7 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); String b = sc.next(); int sum = 0; for (int i = 0; i < a; i++) { sum += Integer.parseInt(b.substring(i, i + 1)); //.. 2021. 2. 2.
[๋ฐฑ์ค€ ์•Œ๊ณ ๋ฆฌ์ฆ˜] 11654๋ฒˆ - ์•„์Šคํ‚ค ์ฝ”๋“œ 8. ๋ฌธ์ž์—ด - ์•„์Šคํ‚ค ์ฝ”๋“œ ๋ฌธ์ œ) ์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž, ๋Œ€๋ฌธ์ž, ์ˆซ์ž 0-9์ค‘ ํ•˜๋‚˜๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ, ์ฃผ์–ด์ง„ ๊ธ€์ž์˜ ์•„์Šคํ‚ค ์ฝ”๋“œ๊ฐ’์„ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. ์ž…๋ ฅ ์ถœ๋ ฅ A 65 ์ž…๋ ฅ ์ถœ๋ ฅ C 67 ์ž…๋ ฅ ์ถœ๋ ฅ 0 48 ์ž…๋ ฅ ์ถœ๋ ฅ 9 57 ์ž…๋ ฅ ์ถœ๋ ฅ a 97 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String n = sc.nextLine(); int result = n.charAt(0); // ๋ฌธ์ž์—ด์„ char๋กœ ๋ฐ˜ํ™˜ํ•˜๋Š” ๋ฉ”์„œ๋“œ System.out.print(result); } } for๋ฌธ์œผ๋กœ ํ•˜๋‹ค๊ฐ€ ์ข‹์€ ๋ฉ”์„œ๋“œ๋ฅผ ๋ฐœ๊ฒฌ! ์—ญ์‹œ.. 2021. 2. 2.
[๋ฐฑ์ค€ ์•Œ๊ณ ๋ฆฌ์ฆ˜] 15596๋ฒˆ - ์ •์ˆ˜ N๊ฐœ์˜ ํ•ฉ 7. ํ•จ์ˆ˜ - ์ •์ˆ˜ N๊ฐœ์˜ ํ•ฉ ๋ฌธ์ œ) ์ •์ˆ˜ n๊ฐœ๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ, n๊ฐœ์˜ ํ•ฉ์„ ๊ตฌํ•˜๋Š” ํ•จ์ˆ˜๋ฅผ ์ž‘์„ฑํ•˜์‹œ์˜ค. Java: long sum(int[] a); (ํด๋ž˜์Šค ์ด๋ฆ„: Test) a: ํ•ฉ์„ ๊ตฌํ•ด์•ผ ํ•˜๋Š” ์ •์ˆ˜ n๊ฐœ๊ฐ€ ์ €์žฅ๋˜์–ด ์žˆ๋Š” ๋ฐฐ์—ด (0 ≤ a[i] ≤ 1,000,000, 1 ≤ n ≤ 3,000,000) ๋ฆฌํ„ด๊ฐ’: a์— ํฌํ•จ๋˜์–ด ์žˆ๋Š” ์ •์ˆ˜ n๊ฐœ์˜ ํ•ฉ public class Test { long sum(int[] a) { long ans = 0; for (int i = 0; i < a.length; i++) { ans += a[i]; } return ans; } } ์ถœ๋ ฅ๊นŒ์ง€๋Š” ์•ˆํ•˜๊ณ  ๊ทธ๋ƒฅ ์ฃผ์–ด์ง„ ์ฝ”๋“œ ์•ˆ์—์„œ๋งŒ ์ˆ˜์ •ํ•˜๋ผ๋Š” ๋œป์ด์—ˆ๋‚˜๋ณด๋‹ค 2021. 2. 2.
[๋ฐฑ์ค€ ์•Œ๊ณ ๋ฆฌ์ฆ˜] 2562๋ฒˆ - ์ตœ๋Œ“๊ฐ’ 6. 1์ฐจ์› ๋ฐฐ์—ด - ์ตœ๋Œ“๊ฐ’ ๋ฌธ์ œ) 9๊ฐœ์˜ ์„œ๋กœ ๋‹ค๋ฅธ ์ž์—ฐ์ˆ˜๊ฐ€ ์ฃผ์–ด์งˆ ๋•Œ, ์ด๋“ค ์ค‘ ์ตœ๋Œ“๊ฐ’์„ ์ฐพ๊ณ  ๊ทธ ์ตœ๋Œ“๊ฐ’์ด ๋ช‡ ๋ฒˆ์งธ ์ˆ˜์ธ์ง€๋ฅผ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ์„œ๋กœ ๋‹ค๋ฅธ 9๊ฐœ์˜ ์ž์—ฐ์ˆ˜ 3, 29, 38, 12, 57, 74, 40, 85, 61์ด ์ฃผ์–ด์ง€๋ฉด, ์ด๋“ค ์ค‘ ์ตœ๋Œ“๊ฐ’์€ 85์ด๊ณ , ์ด ๊ฐ’์€ 8๋ฒˆ์งธ ์ˆ˜์ด๋‹ค. ์ž…๋ ฅ ์ถœ๋ ฅ 3 29 38 12 57 74 40 85 61 85 8 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int max = 0; int cnt = 0; int[] num = new int[10]; // ์ˆซ์ž.. 2021. 2. 2.
[๋ฐฑ์ค€ ์•Œ๊ณ ๋ฆฌ์ฆ˜] 10818๋ฒˆ - ์ตœ์†Œ, ์ตœ๋Œ€ 6. 1์ฐจ์› ๋ฐฐ์—ด - ์ตœ์†Œ, ์ตœ๋Œ€ ๋ฌธ์ œ) N๊ฐœ์˜ ์ •์ˆ˜๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ์ด๋•Œ, ์ตœ์†Ÿ๊ฐ’๊ณผ ์ตœ๋Œ“๊ฐ’์„ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. ์ž…๋ ฅ ์ถœ๋ ฅ 5 20 10 35 30 7 7 35 import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] num = new int[n]; for (int i = 0; i < n; i++) { num[i] = sc.nextInt(); } Arrays.sort(num); System.out.print(num[0] + " "); Sys.. 2021. 2. 2.
๋ฐ˜์‘ํ˜•