๋ชฉ๋ก๐ฆฅ ์ฝํ /Programmers (25)
๐ ๊ณต๋ถํ๋ ์ง์ง์ํ์นด๋ ์ฒ์์ด์ง?
๋ ์ ์ a, b๊ฐ ์ฃผ์ด์ง ๋ ๋ค์๊ณผ ๊ฐ์ ํํ์ ๊ณ์ฐ์์ ์ถ๋ ฅํ๋ ์ฝ๋๋ฅผ ์์ฑํด ๋ณด์ธ์. #include using namespace std; int main(void) { int a; int b; cin >> a >> b; cout
๋ค์๊ณผ ๊ฐ์ด ์ถ๋ ฅํ๋๋ก ์ฝ๋๋ฅผ ์์ฑํด ์ฃผ์ธ์. // ์ถ๋ ฅ ์์ !@#$%^&*(\'"?:;โ #include using namespace std; int main(void) { cout
์์ด ์ํ๋ฒณ์ผ๋ก ์ด๋ฃจ์ด์ง ๋ฌธ์์ด str์ด ์ฃผ์ด์ง๋๋ค. ๊ฐ ์ํ๋ฒณ์ ๋๋ฌธ์๋ ์๋ฌธ์๋ก, ์๋ฌธ์๋ ๋๋ฌธ์๋ก ๋ณํํด์ ์ถ๋ ฅํ๋ ์ฝ๋๋ฅผ ์์ฑํด ๋ณด์ธ์. #include #include using namespace std; int main(void) { string str; cin >> str; // & : ์ฐธ์กฐ(reference) ํ์ // ํด๋น ๋ณ์๋ฅผ ๋ณต์ฌํ์ง ์๊ณ ๊ฐ์ ๋ณ๊ฒฝ for (char& c : str) { // ๋๋ฌธ์์ธ์ง ํ๋ณ if (isupper(c)) { // ๋๋ฌธ์๋ฅผ ์๋ฌธ์๋ก ๋ณํ c = tolower(c); // ์๋ฌธ์์ธ์ง ํ๋ณ } else if (islower(c)) { // ์๋ฌธ์๋ฅผ ๋๋ฌธ์๋ก ๋ณํ c = toupper(c); } } cout
๋ฌธ์์ด str๊ณผ ์ ์ n์ด ์ฃผ์ด์ง๋๋ค. str์ด n๋ฒ ๋ฐ๋ณต๋ ๋ฌธ์์ด์ ๋ง๋ค์ด ์ถ๋ ฅํ๋ ์ฝ๋๋ฅผ ์์ฑํด ๋ณด์ธ์ #include #include using namespace std; int main(void) { string str; int n; cin >> str >> n; for(int i =0 ; i < n ; i++){ cout
์ ์ a์ b๊ฐ ์ฃผ์ด์ง๋๋ค. ๊ฐ ์๋ฅผ ์ ๋ ฅ๋ฐ์ ์ ์ถ๋ ฅ ์์ ๊ฐ์ ํ์์ผ๋ก ์ถ๋ ฅํ๋ ์ฝ๋๋ฅผ ์์ฑํด ๋ณด์ธ์. #include using namespace std; int main(void) { int a; int b; cin >> a >> b; cout
๋ฌธ์์ด str์ด ์ฃผ์ด์ง ๋, str์ ์ถ๋ ฅํ๋ ์ฝ๋๋ฅผ ์์ฑํด ๋ณด์ธ์ #include #include using namespace std; int main(void) { string str; getline(cin, str); // ๋ฌธ์์ด์ ์ ๋ ฅ๋ฐ์ cout
์ค์์๋ ๋ ธ๋์์ผ๋ก ์น ํด์ ธ ์๊ณ ํ ๋๋ฆฌ 1์ค์ ๊ฐ์์ผ๋ก ์น ํด์ ธ ์๋ ๊ฒฉ์ ๋ชจ์ ์นดํซ Leo๊ฐ ๋ณธ ์นดํซ์์ ๊ฐ์ ๊ฒฉ์์ ์ brown, ๋ ธ๋์ ๊ฒฉ์์ ์ yellow๊ฐ ๋งค๊ฐ๋ณ์๋ก ์ฃผ์ด์ง ๋ ์นดํซ์ ๊ฐ๋ก, ์ธ๋ก ํฌ๊ธฐ๋ฅผ ์์๋๋ก ๋ฐฐ์ด์ ๋ด์ return ์นดํซ์ ๊ฐ๋ก ๊ธธ์ด๋ ์ธ๋ก ๊ธธ์ด์ ๊ฐ๊ฑฐ๋, ์ธ๋ก ๊ธธ์ด๋ณด๋ค ๊ธธ๋ค def solution(brown, yellow): # ์นดํซ ๋์ด total = brown + yellow # ๊ฐ๋ก a, ์ธ๋ก b for a in range(total, 2, -1) : if total % a == 0 : b = total // a # ํ ๋๋ฆฌ๊ธธ์ด(2)๋งํผ ๋นผ์ฃผ๊ณ ๋ฉด์ ์ ๊ตฌํจ # yellow์ ๋ฉด์ ๊ณผ ๊ฐ๋ค๋ฉด return if yellow == (b-2) * (a-2): return [a..
์ฝ๋๋ ๋งค์ผ ๋ค๋ฅธ ์ท์ ์กฐํฉํ์ฌ ์ ๋๊ฒ์ ์ข์ํจ ๊ฐ ์ข ๋ฅ๋ณ๋ก ์ต๋ 1๊ฐ์ง ์์๋ง ์ฐฉ์ฉ ์ฐฉ์ฉํ ์์์ ์ผ๋ถ๊ฐ ๊ฒน์น๋๋ผ๋, ๋ค๋ฅธ ์์์ด ๊ฒน์น์ง ์๊ฑฐ๋, ํน์ ์์์ ์ถ๊ฐ๋ก ๋ ์ฐฉ์ฉํ ๊ฒฝ์ฐ์๋ ์๋ก ๋ค๋ฅธ ๋ฐฉ๋ฒ์ผ๋ก ์ท์ ์ฐฉ์ฉํ ๊ฒ์ผ๋ก ๊ณ์ฐ ์ฝ๋๋ ํ๋ฃจ์ ์ต์ ํ ๊ฐ์ ์์์ ์ ์ ์ฝ๋๊ฐ ๊ฐ์ง ์์๋ค์ด ๋ด๊ธด 2์ฐจ์ ๋ฐฐ์ด clothes๊ฐ ์ฃผ์ด์ง ๋ ์๋ก ๋ค๋ฅธ ์ท์ ์กฐํฉ์ ์๋ฅผ return clothes์ ๊ฐ ํ์ [์์์ ์ด๋ฆ, ์์์ ์ข ๋ฅ] ์ฝ๋๊ฐ ๊ฐ์ง ์์์ ์๋ 1๊ฐ ์ด์ 30๊ฐ ์ดํ ๊ฐ์ ์ด๋ฆ์ ๊ฐ์ง ์์์ ์กด์ฌํ์ง ์์ clothes์ ๋ชจ๋ ์์๋ ๋ฌธ์์ด ๋ชจ๋ ๋ฌธ์์ด์ ๊ธธ์ด๋ 1 ์ด์ 20 ์ดํ์ธ ์์ฐ์, ์ํ๋ฒณ ์๋ฌธ์ ๋๋ '_' def solution(clothes): closet = {} answer..