Banner

My Tech Blog (์ฝ”๋“œ)

โœ… ๋ฌธ์ œ๋ฌธ์ž์—ด ํ˜•ํƒœ์˜ 2์ง„์ˆ˜๋ฅผ ์ž…๋ ฅ๋ฐ›์•„ 10์ง„์ˆ˜๋กœ ๋ฐ”๊พธ๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. โœ… ์ฝ”๋“œimport java.util.Scanner;public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String str = sc.next(); int base = 1; int result = 0; for (int i = str.length()-1 ; i >= 0; i--) { if(str.charAt(i) == '1'){ result += base; } ..
โœ… ๋ฌธ์ œ๊ทธ๋ฆผ๊ณผ ๊ฐ™์ด ๋Œ€์‹œ('_') ๋ฌธ์ž๋กœ ๊ตฌ์„ฑ๋œ ํ˜•ํƒœ์˜ ์ˆซ์ž๋ฅผ ์ฃผ์–ด์ง„ ์ˆซ์ž์™€ ๊ฐ™์ด ์ถœ๋ ฅํ•˜๊ณ  ์‹ถ์„ ๋•Œ ์‚ฌ์šฉ๋˜๋Š” ๋Œ€์‹œ์˜ ๊ฐœ์ˆ˜๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜๋ผ.โœ… ์ฝ”๋“œimport java.util.Scanner;public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int[] c = { 6, 2, 5, 5, 4, 5, 6, 3, 7, 6 }; System.out.print("์ฒซ์ž๋ฆฌ 0์„ ์ œ์™ธํ•œ ์ˆซ์ž๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š” >> "); String nums = sc.nextLine(); int result = 0; for (int i = 0; i > " + result); sc.close()..
โœ… ๋ฌธ์ œ ์ž…๋ ฅ๋œ ๊ฐ’ ๊ทธ๋Œ€๋กœ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ ์งœ๊ธฐ โ€‹๐Ÿ“ฅ ์ž…๋ ฅ ์ž…๋ ฅ์ด ์ฃผ์–ด์ง„๋‹ค. ์ž…๋ ฅ์€ ์ตœ๋Œ€ 100์ค„๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ๊ณ , ์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž, ๋Œ€๋ฌธ์ž, ๊ณต๋ฐฑ, ์ˆซ์ž๋กœ๋งŒ ์ด๋ฃจ์–ด์ ธ ์žˆ๋‹ค. ๊ฐ ์ค„์€ 100๊ธ€์ž๋ฅผ ๋„˜์ง€ ์•Š์œผ๋ฉฐ, ๋นˆ ์ค„์ด ์ฃผ์–ด์งˆ ์ˆ˜๋„ ์žˆ๊ณ , ๊ฐ ์ค„์˜ ์•ž ๋’ค์— ๊ณต๋ฐฑ์ด ์žˆ์„ ์ˆ˜๋„ ์žˆ๋‹ค. โ€‹๐Ÿ“ฅ ์ถœ๋ ฅ ์ž…๋ ฅ ๋ฐ›์€ ๊ทธ๋Œ€๋กœ ์ถœ๋ ฅํ•œ๋‹ค. โ€‹ ๐Ÿ’ก ํ’€์ด 11718๋ฒˆ๊ณผ ์œ ์‚ฌํ•œ ๋ฌธ์ œ๋กœ ๋„์–ด์“ฐ๊ธฐ๋ฅผ ํฌํ•จํ•œ ๋ฌธ์ž์—ด์„ ์ž…๋ ฅ๋ฐ›์•„ ๊ทธ๋Œ€๋กœ ์ถœ๋ ฅํ•ด์ฃผ๋ฉด ๋œ๋‹ค. ์ž…๋ ฅ์ด ๋ช‡ ์ค„ ๋“ค์–ด์˜ค๋Š”์ง€ ์ฃผ์–ด์ง€์ง€ ์•Š์•˜๊ธฐ ๋•Œ๋ฌธ์—, ๊ณ„์† ์ž…๋ ฅ์ด ๋“ค์–ด์˜จ๋‹ค๊ณ  ๊ฐ€์ •ํ•˜๊ณ  while-loop๋ฅผ ์ด์šฉํ•ด ์ž…๋ ฅ์„ ๋ฐ›๊ณ , ์ž…๋ ฅ๋ฐ›์€ ๊ฒƒ์ด ์—†์œผ๋ฉด loop์„ ์ข…๋ฃŒํ•ด ์ฃผ๋ฉด ๋œ๋‹ค. input()๊ณผ sys.stdin.readlines()๋ฅผ ์ด์šฉํ•˜์—ฌ ๋‘ ๊ฐ€์ง€๋กœ ํ’€์ดํ–ˆ๋‹ค. โœ… 1. Buffered..
โœ… ๋ฌธ์ œ ์ž…๋ ฅ๋œ ๊ฐ’ ๊ทธ๋Œ€๋กœ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ ์งœ๊ธฐ โ€‹๐Ÿ“ฅ ์ž…๋ ฅ ์ž…๋ ฅ์ด ์ฃผ์–ด์ง„๋‹ค. ์ž…๋ ฅ์€ ์ตœ๋Œ€ 100์ค„๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ๊ณ , ์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž, ๋Œ€๋ฌธ์ž, ๊ณต๋ฐฑ, ์ˆซ์ž๋กœ๋งŒ ์ด๋ฃจ์–ด์ ธ ์žˆ๋‹ค. ๊ฐ ์ค„์€ 100๊ธ€์ž๋ฅผ ๋„˜์ง€ ์•Š์œผ๋ฉฐ, ๋นˆ ์ค„์€ ์ฃผ์–ด์ง€์ง€ ์•Š๋Š”๋‹ค. ๋˜, ๊ฐ ์ค„์€ ๊ณต๋ฐฑ์œผ๋กœ ์‹œ์ž‘ํ•˜์ง€ ์•Š๊ณ , ๊ณต๋ฐฑ์œผ๋กœ ๋๋‚˜์ง€ ์•Š๋Š”๋‹ค. โ€‹๐Ÿ“ฅ ์ถœ๋ ฅ ์ž…๋ ฅ ๋ฐ›์€ ๊ทธ๋Œ€๋กœ ์ถœ๋ ฅํ•œ๋‹ค. โ€‹ ๐Ÿ’ก ํ’€์ด ์ฒ˜์Œ์—๋Š” ์—ฅ? ์ด๊ฒŒ ์ •๋‹ต๋ฅ  30ํผ์„ผํŠธ ๋ฐ–์— ์•ˆ ๋œ๋‹ค๊ตฌ? ์ƒ๊ฐํ–ˆ๋Š”๋ฐ ๋‚˜๋„ ํ‹€๋ ธ๋‹ค. ๋ณดํ†ต์€ ๋ฌธ์ œ์—์„œ n๊ฐœ์˜ ์ค„์— ์ž…๋ ฅ์„ ๋ฐ›์œผ๋ผ๋Š” ๋ฐ˜๋ณต ํšŸ์ˆ˜๊ฐ€ ์ฃผ์–ด์ง€๋Š”๋ฐ ์ด ๋ฌธ์ œ์—์„œ๋Š” n์„ ์•Œ๋ ค์ฃผ์ง€ ์•Š๋Š”๋‹ค. ์ž…๋ ฅ๊ฐ’์ด ๋ช‡ ๋ฒˆ ์ฃผ์–ด์ง€๋Š”์ง€๋Š” ๋ชจ๋ฅด์ง€๋งŒ ์ž…๋ ฅ๋œ ๊ฐ’ ๊ทธ๋Œ€๋กœ ์ถœ๋ ฅํ•ด์•ผํ•˜๋Š” ๋ฌธ์ œ์ด๋‹ค. ๊ทธ๋ž˜์„œ while๋ฌธ์„ ๋Œ๋ ค์ฃผ๊ณ  ์กฐ๊ฑด์„ ๋งŒ์กฑํ•˜๋ฉด break๋ฅผ ๊ฑธ์–ด ์ฃผ๋Š” ๊ฒŒ ํ•ต์‹ฌ์ด๋‹ค. input..
โœ… ๋ฌธ์ œ  [์ž…๋ ฅ]1. N๊ณผ X๋ฅผ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค.2. N๊ฐœ์˜ ์ •์ˆ˜๋ฅผ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค. (๋ฐ˜๋ณต๋ฌธ) [์ถœ๋ ฅ]3. N๊ฐœ์˜ ์ˆซ์ž ์ค‘ X๋ณด๋‹ค ์ž‘์€ ์ˆ˜๋งŒ ์ถœ๋ ฅํ•œ๋‹ค. โœ… ์ฝ”๋“œimport java.util.Scanner;public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("N ์ž…๋ ฅ >> "); int n = sc.nextInt(); System.out.print("X ์ž…๋ ฅ >> "); int x = sc.nextInt(); int[] nums = new int[n]; for (int ..
โœ… ๋ฌธ์ œ์•„๋ž˜์™€ ๊ฐ™์€ 2์ฐจ์› ๋ฐฐ์—ด์„ ์™ผ์ชฝ์œผ๋กœ 90๋„ ํšŒ์ „ํ•˜์—ฌ ์ถœ๋ ฅํ•˜์‹œ์˜ค.โœ… ์ฝ”๋“œpublic class Main { public static void main(String[] args) { int[][] num = new int[5][5]; int count = 1; for (int i = 0; i  โœ… ์ถ”๋ก  ๊ณผ์ • 1. ์›๋ณธ๋ฐฐ์—ด ์ถœ๋ ฅ๋น„๊ต๋ฅผ ์œ„ํ•ด์„œ ์›๋ณธ ๋ฐฐ์—ด์„ ์ถœ๋ ฅํ•˜๋Š” ์ฝ”๋“œ๋ฅผ ๋จผ์ € ์ž‘์„ฑํ•ด ์ฃผ์—ˆ๋‹ค. 25์นธ์งœ๋ฆฌ ๋ฐฐ์—ด์„ ์„ ์–ธํ•ด์ฃผ๊ณ  count ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•ด์„œ 1๋กœ ์ดˆ๊ธฐํ™” ์‹œ์ผœ์ค€ ๋’ค, for๋ฌธ์„ ๋Œ๋ฆฌ๋ฉฐ count๋ฅผ 1์”ฉ ์ฆ๊ฐ€์‹œํ‚ค๋ฉฐ ๋ฐฐ์—ด์— ์ง‘์–ด ๋„ฃ์–ด ์ฃผ์—ˆ๋‹ค. ์ด์ œ ๋‹ค์‹œ for๋ฌธ์„ ๋Œ๋ ค์„œ ๋ฐฐ์—ด ์š”์†Œ๋“ค์„ ์ถœ๋ ฅํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค. "\t"์„ ์‚ฌ์šฉํ•ด์ฃผ๋ฉด ์–‘ ์˜†์— ํƒญํ‚ค๋งŒํผ ๊ฐ„๊ฒฉ์„ ๋„ฃ์–ด์„œ ์ถœ๋ ฅํ•  ์ˆ˜ ์žˆ๋‹ค.  2. ๋ฐ˜์‹œ๊ณ„๋ฐฉํ–ฅ์œผ๋กœ 9..
โœ… ๋ฌธ์ œ ์•„๋ž˜์™€ ๊ฐ™์ด ์ˆซ์ž๊ฐ€ ๋‹ด๊ธด 1์ฐจ์› ๋ฐฐ์—ด์ด ์ฃผ์–ด์กŒ์„ ๋•Œ, ๋‘ ๊ฐœ์˜ ์ˆซ์ž๋ฅผ ๋ฝ‘์•„ ์„œ๋กœ์˜ ๊ฑฐ๋ฆฌ๋ฅผ ๋น„๊ตํ•œ ํ›„ ๊ฑฐ๋ฆฌ๊ฐ€ ๊ฐ€์žฅ ์ž‘์€ ์ˆซ์ž์˜ ์œ„์น˜(index)๋ฅผ ์ถœ๋ ฅํ•˜์‹œ์˜ค. โœ… ์ฝ”๋“œpublic class Main { public static void main(String[] args) { int[] point = { 92, 32, 52, 9, 81, 2, 68 }; int dist = 1000000000; int[] result = new int[2]; for (int i = 0; i Math.abs(point[i] - point[j])) { dist = Math.abs(point[i] - point[j]); result[0] = i; result[1] = j; } ..
โœ… ๋ฌธ์ œ ๋‘ ์ž์—ฐ์ˆ˜ A,B๋ฅผ ์ž…๋ ฅ๋ฐ›๊ณ  ๊ฐ ์ค„์— A+B, A-B, A*B, A/B, A%B๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ์‚ฌ์น™์—ฐ์‚ฐ ๋ฌธ์ œ โœ… ์‚ฐ์ˆ ์—ฐ์‚ฐ์ž ์ •๋ฆฌ A + B A์™€ B๋ฅผ ๋”ํ•œ๋‹ค. A - B A์—์„œ B๋ฅผ ๋บ€๋‹ค. A * B A์™€ B๋ฅผ ๊ณฑํ•œ๋‹ค. A / B A๋ฅผ B๋กœ ๋‚˜๋ˆˆ๋‹ค => ๊ฒฐ๊ณผ ๊ฐ’์ด floatํ˜•์œผ๋กœ ๋ฐ˜ํ™˜(์ •์ˆ˜ ์•„๋‹Œ ์‹ค์ˆ˜๋กœ ๋ฐ˜ํ™˜) A // B A๋ฅผ B๋กœ ๋‚˜๋ˆˆ ๋ชซ์„ ๊ตฌํ•œ๋‹ค. A % B A๋ฅผ B๋กœ ๋‚˜๋ˆˆ ๋‚˜๋จธ์ง€๋ฅผ ๊ตฌํ•œ๋‹ค. A ** B A์˜ B์ œ๊ณฑ โœ… ์ฝ”๋“œ 1) input()a,b = input().split() a = int(a) b = int(b) print(a+b) print(a-b) print(a*b) print(int(a/b)) // print(a//b) print(a%b) ์‚ฐ์ˆ ์—ฐ์‚ฐ์ž '/' ํŒŒ์ด์ฌ์—์„œ / ์—ฐ์‚ฐ์ž๋กœ ๋‚˜..
์ธ์ ˆ๋ฏธ์˜€๋˜๊ฒƒ
'์ฝ”๋“œ' ํƒœ๊ทธ์˜ ๊ธ€ ๋ชฉ๋ก (14 Page)
์ƒ๋‹จ์œผ๋กœ