๊ทธ๋ƒฅ ๊ฐ„๋‹จํ•œ ์ •๋ ฌ ๋ฌธ์ œ

Solution rust soulution kotlin solution Memo ๊ฐ„๋‹จํ•œ ์ •๋ ฌ ๋ฌธ์ œ ๋Ÿฌ์ŠคํŠธ ์ž…์ถœ๋ ฅ์„ ์ข€ ์ฐพ์•„์„œ ์จ๋ดค๋‹ค. // Baekjoon - 11650 // https://www.acmicpc.net/problem/11650 use std::io::{self, Read, Write}; fn main() { let stdin = io::stdin(); let stdout = io::stdout(); let mut stdin = stdin.lock(); let mut stdout = stdout.lock(); let mut input = String::new(); stdin.read_to_string(&mut input).unwrap(); let mut lines = input.lines(); let n: usize = lines.next().unwrap().parse().unwrap(); let mut vec: Vec<(i32, i32)> = Vec::with_capacity(n); for _ in 0....

April 30, 2025

์ˆœ์—ด

Solution cpp soulution kotlin solution Memo ์ˆœ์—ด ๊ตฌํ˜„ ๋ฌธ์ œ cpp ํ’€์ด๋Š” next_permutation์„ ์ด์šฉํ•ด์„œ ๊ฐ„๋‹จํ•˜๊ฒŒ ํ–ˆ๋‹ค. int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); // ๋ฌธ์ œ ํ•ด๊ฒฐ ์ฝ”๋“œ ์ž‘์„ฑ int n; cin >> n; vector<int> arr; for (int i = 1; i < n + 1; i++) { arr.push_back(i); } do { for (int i: arr) { cout << i << ' '; } cout << '\n'; } while (next_permutation(arr.begin(), arr.end())); return 0; } ๋ฌธ์ œ๋Š” ์ฝ”ํ‹€๋ฆฐ ๊ตฌํ˜„ํ•˜๋‹ค๊ฐ€ ๋ฐœ์ƒํ–ˆ๋Š”๋ฐ, ์ฒ˜์Œ์—๋Š” ์•„๋ž˜์ฒ˜๋Ÿผ ๊ตฌํ˜„ํ–ˆ๋‹ค....

April 28, 2025

๊ฐ„๋‹จํ•œ ์กฐํ•ฉ2

Solution cpp soulution kotlin solution Memo ๊ทธ๋ƒฅ ๊ฐ„๋‹จํ•œ ์กฐํ•ฉ ๊ตฌํ˜„ ๋ฌธ์ œ 2 ์กฐํ•ฉ์€ ๊ทธ๋ƒฅ ๊ตฌํ•˜๊ณ , valid ์ดํ›„ ์ถœ๋ ฅํ•ด์ฃผ๋Š” ์ •๋„ ๋ณ€์ˆ˜๋ฅผ ๋„ˆ๋ฌด ๋‚œ์žกํ•˜๊ฒŒ ์จ์„œ ์Šต๊ด€์ ์œผ๋กœ ์ •๋ฆฌํ•ด์•ผํ•  ๊ฒƒ ๊ฐ™๋‹ค. bool is_valid_password(vector<char> &chars) { int vowel_count = 0; int consonant_count = 0; for (char c : chars) { if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') { vowel_count++; } else if (c >= 'a' && c <= 'z') { consonant_count++; } } return (consonant_count >= 2 && vowel_count >= 1); } void combination(vector<char> &characters, int idx, int level, vector<char> &tmp) { if (level == plen) { if (is_valid_password(tmp)) { for (char c : tmp) { cout << c; } cout << '\n'; } return; } for (int i = idx; i < characters....

April 28, 2025

cantore ์žฌ๊ท€

Solution cpp soulution kotlin solution Memo ์žฌ๊ท€ ๊ตฌํ˜„ ๋ฌธ์ œ bottomup ๋ฐฉ์‹๋„ ์žˆ๋Š”๋ฐ ์‹œ๊ฐ„๋ณต์žก๋„๋Š” ๋˜‘๊ฐ™์•„์„œ ๊ทธ๋ƒฅ ํ–ˆ๋‹ค.

April 28, 2025

Combination

Solution cpp soulution kotlin solution Memo ๊ทธ๋ƒฅ ๊ฐ„๋‹จํ•œ ์กฐํ•ฉ ๊ตฌํ˜„ ๋ฌธ์ œ cpp๋Š” ํŠน์ง•์ ์ธ๊ฑด ์—†๊ณ  ๊ทธ๋ƒฅ ์žฌ๊ท€๋กœ ํ–ˆ๋‹ค. fun List<Int>.findLottoCombinations(result: MutableList<Int> = mutableListOf(), index: Int = 0) { if (result.size == 6) { println(result.joinToString(" ")) return } if (result.size + (size - index) < 6) return for (i in index until size) { result.add(this[i]) findLottoCombinations(result, i + 1) result.removeAt(result.lastIndex) } } fun main() = with(BufferedReader(InputStreamReader(System.`in`))) { generateSequence { readLine() } .takeWhile { it !...

April 28, 2025

์ฝ”๋”ฉ ์ธํ„ฐ๋ทฐ ์—ฐ์Šต ๐Ÿงฉ

๋งค์ผ ๋‘?๋ฌธ์ œ ๋„ค?๊ฐ€์ง€ ํ’€์ด

April 28, 2025

์ฝ”ํ‹€๋ฆฐ ์ฝ”๋ฃจํ‹ด ๐Ÿ‘พ

kotlin coroutines ์ฑ… ์ •๋ฆฌ

April 28, 2025

์ฝ”ํ‹€๋ฆฐ ํ•จ์ˆ˜ํ˜• ํ”„๋กœ๊ทธ๋ž˜๋ฐ

ํ•จ์ˆ˜ ํƒ€์ž… ํ•จ์ˆ˜ ํƒ€์ž… ์ •์˜ (T) -> Boolean : Boolean์„ ๋ฐ˜ํ™˜ํ•˜๋Š” ํ•จ์ˆ˜ Predicate (T) -> R : ๊ฐ’ ํ•˜๋‚˜๋ฅผ ๋‹ค๋ฅธ ๊ฐ’์œผ๋กœ ๋ณ€ํ™˜ํ•˜๋Š” ํ•จ์ˆ˜ transfrom (T) -> Unit : Unit์„ ๋ฐ˜ํ™˜ํ•˜๋Š” ํ•จ์ˆ˜ operation ํ•จ์ˆ˜ ํƒ€์ž… ํ™œ์šฉ invoke๋ผ๋Š” ๋‹จ ํ•˜๋‚˜์˜ ๋ฉ”์„œ๋“œ๋งŒ ์ œ๊ณตํ•จ, ๋ช…์‹œ์  invokeํ˜ธ์ถœ๊ณผ ()์—ฐ์‚ฐ์ž๋กœ ํ˜ธ์ถœ ํ•จ์ˆ˜ํƒ€์ž… ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ()? ๋กœ ๊ฐ์‹ธ์„œ ๋„๋Ÿฌ๋ธ”ํ•จ์„ ํ‘œํ˜„ํ•  ์ˆ˜ ์žˆ์Œ (์ด๊ฒฝ์šฐ๋Š” ๋ช…์‹œ์  invoke๋งŒ ๊ฐ€๋Šฅ) named parameter ํ•จ์ˆ˜ ํƒ€์ž…์„ ์ •์˜ ํ•  ๋•Œ โ€™named parameterโ€™๋ฅผ ์‚ฌ์šฉ ๊ฐ€๋Šฅ ์˜ค์ง ๊ฐœ๋ฐœ ํŽธ์˜๋ฅผ ์œ„ํ•œ ๊ฒƒ ์ต๋ช… ํ•จ์ˆ˜ ์ต๋ช…ํ•จ์ˆ˜๋Š” ํ•จ์ˆ˜ ํƒ€์ž… ๊ฐ์ฒด๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” ํ‘œํ˜„์‹ generic, default parameter๋Š” ์ง€์›ํ•˜์ง€ ์•Š์Œ val add2 = fun(a: Int, b: Int) = a + b ์ต๋ช…ํ•จ์ˆ˜ ์ž์ฒด๋Š” ์š”์ฆ˜ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค๊ณ  ํ•จ ๋žŒ๋‹ค๊ฐ€ ๋” ์งง๊ณ  ์ง€์›์ด ๋” ์ž˜๋จ ์ธํ…”๋ฆฌ์ œ์ด๋Š” ๋žŒ๋‹ค๋งŒ ํžŒํŠธ๋ฅผ ์ œ๊ณต ๊ทธ๋ž˜๋„ ์•„๋ž˜์™€ ๊ฐ™์€ ์ƒํ™ฉ์—๋Š” ์•„์ง ์œ ์šฉ return ๋ฒ”์œ„ ๋ช…ํ™•ํžˆ ๊ตฌ๋ถ„ํ•˜๊ณ  ์‹ถ์„ ๋•Œ ํƒ€์ž… ๋ช…์‹œ์  ์„ ์–ธ (๋žŒ๋‹ค๋ณด๋‹ค ๊น”๋”) return์„ ๋ช…์‹œ์ ์œผ๋กœ ์‚ฌ์šฉํ•ด์•ผ ํ•  ๋•Œ ๊ณ ์ฐจํ•จ์ˆ˜ ์ธ์ž๊ฐ€ 2๊ฐœ ์ด์ƒ์ด๊ณ  ๋ณต์žกํ•  ๋•Œ ๋žŒ๋‹ค ํ‘œํ˜„์‹ ์ฝ”ํ‹€๋ฆฐ์—์„œ ๋žŒ๋‹ค ํ‘œํ˜„์‹(lambda expression)์€ return์„ ํ—ˆ์šฉํ•˜์ง€ ์•Š๋Š” ์ด์œ ๋Š”, ๋žŒ๋‹ค๊ฐ€ ๊ทธ ์ž์ฒด๋กœ โ€œ๋…๋ฆฝ์ ์ธ ์‹คํ–‰ ํ๋ฆ„โ€์„ ๊ฐ–๋Š” ํ•จ์ˆ˜๊ฐ€ ์•„๋‹ˆ๋ผ, โ€œํ˜ธ์ถœ๋˜๋Š” ์ปจํ…์ŠคํŠธ์— ์˜์กดํ•˜๋Š” ์ž‘์€ ์ฝ”๋“œ ๋ธ”๋กโ€์ด๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค....

April 27, 2025

cpp ps์šฉ ๊ธฐ๋ณธ ๋ฌธ๋ฒ• ๋ฆฌ๋งˆ์ธ๋“œ ๐Ÿ’ก

C++ Grammar and Syntax Guide for Coding Interviews (Algorithms & DS) Core Data Types and Variables Basic Types int x = 5; // Integer long long bigNum = 1LL<<60; // Large integer (note LL suffix) double y = 3.14; // Double precision floating point bool flag = true; // Boolean char c = 'A'; // Character string s = "Hello"; // String (requires #include <string>) Type Modifiers unsigned int positiveOnly = 100; // Only non-negative values const int FIXED = 10; // Cannot be modified after initialization Type Aliases typedef long long ll; // Old style type alias using ll = long long; // Modern style type alias (preferred) Auto Type Deduction auto num = 10; // Compiler deduces type (int in this case) auto it = myVector....

April 26, 2025

ํŒŒ์ด์จ๋‹‰ ํŒŒ์ด์ฌ

1~3์žฅ ๊ธฐ๋ณธ ๋ฌธ๋ฒ• ์ง„์งœ ๊ฐ„๋‹จํ•˜๊ฒŒ ๋ฌธ๋ฒ•์„ ํ›‘๋Š”๋‹ค. 3์žฅ ํ”„๋กœ๊ทธ๋žจ ๊ตฌ์กฐ์™€ ์ œ์–ด ํ๋ฆ„ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ์— ๋Œ€ํ•œ ์กฐ์–ธ ์ฝ”๋“œ์˜ ํŠน์ • ์œ„์น˜์—์„œ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์—†๋Š” ์˜ˆ์™ธ๋Š” ์žก์ง€ ์•Š๋Š”๋‹ค. def read_data(filename): with open(filename, 'rt') as file: rows = [] for line in file: row = line.split() rows.append((row[0], int(row[1]), float(row[2]))) return rows ์œ„์˜ ๊ฒฝ์šฐ ํ•จ์ˆ˜์˜ ์‚ฌ์šฉ์ž๊ฐ€ ์ž˜๋ชป๋œ ํŒŒ์ผ๋ช…์„ ์ฒ˜๋ฆฌํ•  ๊ธฐํšŒ๊ฐ€ ์‚ฌ๋ผ์ง ์˜ˆ์™ธ๋ฅผ ํ˜ธ์ถœ์žํ•œํ…Œ ์ „๋‹ฌํ•˜๋Š”๊ฒŒ ๋ฐ”๋žŒ์งํ•˜๋‹ค๊ณ ํ•จ ํŒŒ์ด์ฌ์€ ๋งค๋ฒˆ ์—๋Ÿฌ ํ™•์ธํ•˜์ง€ ๋ง๊ณ , ์‹คํŒจํ•˜๋„๋ก ๋‚ด๋ฒ„๋ ค๋‘๋ผ๋Š” ์ฒ ํ•™์„ ๊ฐ€์ง. ์˜ˆ์™ธ๋Š” ํ”„๋กœ๊ทธ๋žจ ํ๋ฆ„์„ ์œ„๋กœ โ€œ์ „ํŒŒโ€์‹œ์ผœ์„œ, ์ƒ์œ„ ์ฑ…์ž„ ์ฝ”๋“œ์—์„œ ์ฒ˜๋ฆฌํ•˜๋Š” ๊ฒŒ ์ž์—ฐ์Šค๋Ÿฝ๋‹ค๋Š” ์ ‘๊ทผ ํ ....

April 21, 2025