[c++] ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค :: ํƒ‘ (๋ฌธ์ œ ํ’€์ด, ์ฝ”๋“œ)
Algorithm ๋ฌธ์ œ/ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค 2020. 7. 26. 11:16

ํƒ‘ https://programmers.co.kr/learn/courses/30/lessons/42588?language=cpp ์ฝ”๋“œ #include #include #include using namespace std; vector solution(vector heights) { int heights_len = heights.size(); vector answer(heights_len); stack stk; // index, key for (int i = heights_len - 1; i>0; i--) { if (heights[i - 1] > heights[i]) { answer[i] = i; // stack while (stk.size() != 0) { auto tmp = stk.top(); if (h..

[c++] ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค :: ์นดํŽซ (brute force)
Algorithm ๋ฌธ์ œ/ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค 2020. 5. 28. 21:50

์นดํŽซ ์ฝ”๋“œ #include #include #include using namespace std; vector solution(int brown, int yellow) { vector answer; vector candidate; for (int i = 1; i ๋งž์œผ๋ฉด (๊ฐ€๋กœ, ์„ธ๋กœ) ๊ธธ์ด๋ฅผ ๊ฒฐ๊ณผ vector์— ๋„ฃ์–ด์„œ return brown ๊ฐฏ์ˆ˜ = 2*๊ฐ€๋กœyellow + 2*์„ธ๋กœyellow +4 4 : ์–‘์ชฝ ๋ชจ์„œ๋ฆฌ ๋‹ค๋ฅธ ์‚ฌ๋žŒ์˜ ์ฝ”๋“œ #include #include using namespace std; vector solution(int brown, int red) { int len = brown / 2 + 2; int w = len - 3; int h = 3; while(w >= h){ if(w * h ..

[c++] ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค :: ์ˆซ์ž์•ผ๊ตฌ (brute force)
Algorithm ๋ฌธ์ œ/ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค 2020. 5. 28. 09:00

์ˆซ์ž์•ผ๊ตฌ ์ฝ”๋“œ #include #include using namespace std; bool check(int* arr, vector& bb) { int num = bb[0]; int s = bb[1]; int b = bb[2]; int n[3]; n[0] = num / 100; n[1] = (num - n[0] * 100) / 10; n[2] = (num - n[0] * 100 - n[1] * 10); //strike check int t_num = 0; for (int i = 0; i < 3; i++) { if (n[i] == arr[i]) t_num++; } if (t_num != s) return false; t_num = 0; for (int i = 0; i < 3; i++) { if (n[i]..

[c++] ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค :: ์†Œ์ˆ˜ ์ฐพ๊ธฐ (brute force)
Algorithm ๋ฌธ์ œ/ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค 2020. 5. 24. 10:24

https://programmers.co.kr/learn/courses/30/lessons/42839 ์ฝ”๋“œ #include #include #include #include using namespace std; set res; void test(int num) { if (num num์ด ์ตœ๋Œ€ 9999999 (10^7) if (num%i == 0) return; } res.insert(num); return; } void makePrime(vector& memo,int num) { if (memo.size()==0) return; int size = memo.size(); for (int i = 0; i < size; i++) { // 7 int value = memo[i]; test(num * 10 + v..

[c++] ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค :: ๋ชจ์˜๊ณ ์‚ฌ (brute force)
Algorithm ๋ฌธ์ œ/ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค 2020. 5. 24. 10:14

https://programmers.co.kr/learn/courses/30/lessons/42840 ๋Œ€์ถฉ ํ’€๋ฉด ์‰ฌ์šด ๋ฌธ์ œ. ์ฝ”๋“œ๋ฅผ ๊ฐ„๊ฒฐํ•˜๊ณ  ๋ช…ํ™•ํ•˜๊ฒŒ ์“ฐ๋Š” ๊ฑธ ์—ฐ์Šตํ•˜์ž. ์ฝ”๋“œ #include #include #include using namespace std; vector solution(vector answers) { vector answer; int size = answers.size(); int correct[3] = { 0,0,0 }; int secondList[4] = { 1,3,4,5 }; int thirdList[5] = { 3,1,2,4,5 }; for (int i = 0; icorrect[1]) { if (correct[1] >= correct[2]) { answer.push_back(1..

[c++] ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค :: N์œผ๋กœ ํ‘œํ˜„ (๋‹ค์ด๋‚˜๋ฏน ํ”„๋กœ๊ทธ๋ž˜๋ฐ)
Algorithm ๋ฌธ์ œ/ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค 2020. 4. 2. 09:21

https://programmers.co.kr/learn/courses/30/lessons/42895 ๋ฌธ์ œ ์„ค๋ช… ์•„๋ž˜์™€ ๊ฐ™์ด 5์™€ ์‚ฌ์น™์—ฐ์‚ฐ๋งŒ์œผ๋กœ 12๋ฅผ ํ‘œํ˜„ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. 12 = 5 + 5 + (5 / 5) + (5 / 5) 12 = 55 / 5 + 5 / 5 12 = (55 + 5) / 5 5๋ฅผ ์‚ฌ์šฉํ•œ ํšŸ์ˆ˜๋Š” ๊ฐ๊ฐ 6,5,4 ์ž…๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ์ด์ค‘ ๊ฐ€์žฅ ์ž‘์€ ๊ฒฝ์šฐ๋Š” 4์ž…๋‹ˆ๋‹ค. ์ด์ฒ˜๋Ÿผ ์ˆซ์ž N๊ณผ number๊ฐ€ ์ฃผ์–ด์งˆ ๋•Œ, N๊ณผ ์‚ฌ์น™์—ฐ์‚ฐ๋งŒ ์‚ฌ์šฉํ•ด์„œ ํ‘œํ˜„ ํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ• ์ค‘ N ์‚ฌ์šฉํšŸ์ˆ˜์˜ ์ตœ์†Ÿ๊ฐ’์„ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์ž‘์„ฑํ•˜์„ธ์š”. ์ œํ•œ์‚ฌํ•ญ N์€ 1 ์ด์ƒ 9 ์ดํ•˜์ž…๋‹ˆ๋‹ค. number๋Š” 1 ์ด์ƒ 32,000 ์ดํ•˜์ž…๋‹ˆ๋‹ค. ์ˆ˜์‹์—๋Š” ๊ด„ํ˜ธ์™€ ์‚ฌ์น™์—ฐ์‚ฐ๋งŒ ๊ฐ€๋Šฅํ•˜๋ฉฐ ๋‚˜๋ˆ„๊ธฐ ์—ฐ์‚ฐ์—์„œ ๋‚˜๋จธ์ง€๋Š” ๋ฌด์‹œํ•ฉ..