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

๐Ÿ“ ์•Œ๊ณ ๋ฆฌ์ฆ˜/Programmers

(51)
[PGS] Lv.0 (์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์ž…๋ฌธ) 9์ผ์ฐจ ๋ฌธ์ œ ๊ฐœ๋ฏธ ๊ตฐ๋‹จ int solution(int hp) { int jang = hp / 5; hp -= 5 * jang; int byung = hp / 3; hp -= 3 * byung; int answer = hp + jang + byung; return answer; } ๋ชจ์Šค๋ถ€ํ˜ธ (1) char MORSE_CODE[26][5] = {".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."}; string solution(string letter) { string word = ""; ..
[PGS] Lv.0 (์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์ž…๋ฌธ) 8์ผ์ฐจ ๋ฌธ์ œ ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค C++ ๋ฐฐ์—ด ์ž๋ฅด๊ธฐ vector solution(vector numbers, int num1, int num2) { vector answer; for(num1; num199) { answer.push_back(alpha[age / 100]); age -= 100*(age/100); } if(tmp>9) answer.push_back(alpha[age / 10]); answer.push_back(alpha[age % 10]); return answer; } → ์ƒˆ๋กœ์šด ํ’€์ด string answer = to_string(age); for(auto& v : answer) v += 'a'-'0'; return answer; // for(๋ฐ˜๋ณต๋  ์ง€์—ญ๋ณ€์ˆ˜ : ๋ฐฐ์—ด) -> ์ง€์—ญ๋ณ€์ˆ˜๊ฐ€ ๋ฐฐ์—ด ๊ธธ์ด๋งŒํผ ๋ฐ˜๋ณต๋จ..
[PGS] Lv.0 (์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์ž…๋ฌธ) 7์ผ์ฐจ ๋ฌธ์ œ ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค C++ ํŠน์ • ๋ฌธ์ž ์ œ๊ฑฐํ•˜๊ธฐ string solution(string my_string, string letter) { string answer = ""; answer = regex_replace(my_string, regex(letter), ""); return answer; } ๊ฐ๋„๊ธฐ int solution(int angle) { if(angle==90) return 2; if(angle == 180) return 4; if(angle>0 && angle
[PGS] Lv.1 : ์†Œ์ˆ˜ ๋งŒ๋“ค๊ธฐ https://school.programmers.co.kr/learn/courses/30/lessons/12977 ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr ๋ฌธ์ œ ์„ค๋ช… ์ฃผ์–ด์ง„ ์ˆซ์ž ์ค‘ 3๊ฐœ์˜ ์ˆ˜๋ฅผ ๋”ํ–ˆ์„ ๋•Œ ์†Œ์ˆ˜๊ฐ€ ๋˜๋Š” ๊ฒฝ์šฐ์˜ ๊ฐœ์ˆ˜๋ฅผ ๊ตฌํ•˜๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ์ˆซ์ž๋“ค์ด ๋“ค์–ด์žˆ๋Š” ๋ฐฐ์—ด nums๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, nums์— ์žˆ๋Š” ์ˆซ์ž๋“ค ์ค‘ ์„œ๋กœ ๋‹ค๋ฅธ 3๊ฐœ๋ฅผ ๊ณจ๋ผ ๋”ํ–ˆ์„ ๋•Œ ์†Œ์ˆ˜๊ฐ€ ๋˜๋Š” ๊ฒฝ์šฐ์˜ ๊ฐœ์ˆ˜๋ฅผ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”. ์ œํ•œ์‚ฌํ•ญ nums์— ๋“ค์–ด์žˆ๋Š” ์ˆซ์ž์˜ ๊ฐœ์ˆ˜๋Š” 3๊ฐœ ์ด์ƒ 50๊ฐœ ์ดํ•˜์ž…๋‹ˆ๋‹ค. nums์˜ ๊ฐ ์›์†Œ๋Š” 1 ์ด์ƒ..
[PGS] Lv.1 : ์Œ์–‘ ๋”ํ•˜๊ธฐ https://school.programmers.co.kr/learn/courses/30/lessons/76501 ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr ๋ฌธ์ œ ์„ค๋ช… ์–ด๋–ค ์ •์ˆ˜๋“ค์ด ์žˆ์Šต๋‹ˆ๋‹ค. ์ด ์ •์ˆ˜๋“ค์˜ ์ ˆ๋Œ“๊ฐ’์„ ์ฐจ๋ก€๋Œ€๋กœ ๋‹ด์€ ์ •์ˆ˜ ๋ฐฐ์—ด absolutes์™€ ์ด ์ •์ˆ˜๋“ค์˜ ๋ถ€ํ˜ธ๋ฅผ ์ฐจ๋ก€๋Œ€๋กœ ๋‹ด์€ ๋ถˆ๋ฆฌ์–ธ ๋ฐฐ์—ด signs๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค. ์‹ค์ œ ์ •์ˆ˜๋“ค์˜ ํ•ฉ์„ ๊ตฌํ•˜์—ฌ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”. ์ œํ•œ์‚ฌํ•ญ absolutes์˜ ๊ธธ์ด๋Š” 1 ์ด์ƒ 1,000 ์ดํ•˜์ž…๋‹ˆ๋‹ค. absolutes์˜ ๋ชจ๋“  ์ˆ˜๋Š” ๊ฐ๊ฐ 1 ์ด์ƒ 1,000 ์ดํ•˜์ž…๋‹ˆ..
[PGS] Lv.0 (์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์ž…๋ฌธ) 6์ผ์ฐจ ๋ฌธ์ œ ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ๋ฌธ์ž์—ด ๋’ค์ง‘๊ธฐ string solution(string my_string) { string answer = ""; int len = my_string.length(); for(int i=1; i> n; for(int i=0; i
[PGS] Lv.0 (์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์ž…๋ฌธ) 5์ผ์ฐจ ๋ฌธ์ œ ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์˜ท๊ฐ€๊ฒŒ ํ• ์ธ ๋ฐ›๊ธฐ int solution(int price) { if(price >= 500000) price*=0.8; else if(price >= 300000) price*=0.9; else if(price >= 100000) price*=0.95; return (int)price; } ์•„์ด์Šค ์•„๋ฉ”๋ฆฌ์นด๋…ธ vector solution(int money) { vector answer; answer.push_back(money / 5500); answer.push_back(money % 5500); return answer; } ๋‚˜์ด ์ถœ๋ ฅ int solution(int age) { int answer = 2022+1-age; return answer; } ๋ฐฐ์—ด ๋’ค์ง‘๊ธฐ vector soluti..
[PGS] Lv.0 (์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์ž…๋ฌธ) 4์ผ์ฐจ ๋ฌธ์ œ ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ํ”ผ์ž ๋‚˜๋ˆ  ๋จน๊ธฐ (1) int solution(int n) { int answer = 0; for(int i=1; i= n) return i; } return answer; } ํ”ผ์ž ๋‚˜๋ˆ  ๋จน๊ธฐ (2) int solution(int n) { int answer = 0; for(int i=1; i

728x90