๋ฐ์ํ
๐ค๋ฌธ์ ํด๊ฒฐ
- ์ฃผ์ด์ง ์ง์๋ฅผ ํ์๋ฆฌ ์ฉ ๋ค๋ฅธ๊ฒ์ผ๋ก ๋ฐ๊ฟ์ฃผ๊ธฐ
- 1101(2์ง์) => 0101, 1001, 1111, 1100
- 1221(3์ง์) => 0221, 2221, 1021, 1121, 1201, 1211, 1220, 1222
- ๊ฐ ์์ ๋ํด์ 10์ง์๋ก ๋ฐ๊พธ๊ณ ๋ฆฌ์คํธ(or ๋์
๋๋ฆฌ)์ ๋ฃ๊ธฐ
- 2์ง์ ๋จผ์ ํด์ ๋ค ๋ฃ์ด๋๊ณ
- 3์ง์ ๋ณํํ ๋๋ง๋ค ์ด๋ฏธ ์๋์ง ์ฒดํฌํด์
- ์์ผ๋ฉด break
- ๋ต ์ถ๋ ฅ
๐ป์์ค ์ฝ๋
def convert_decimal(standard, num):
converted_number = 0
for i in range(len(num)):
converted_number += int(num[i]) * (standard ** (len(num) - i - 1))
return converted_number
T = int(input())
for test_case in range(1, T + 1):
answer = 0
binary_number = input()
trinary_number = input()
guess_number_list = {}
for i in range(len(binary_number)):
for j in range(2):
if binary_number[i] == str(j):
continue
wrong_number = str(j)
changed_number = binary_number[:i] + wrong_number + binary_number[i + 1:]
guess_number = convert_decimal(2, changed_number)
guess_number_list[guess_number] = 1
for i in range(len(trinary_number)):
for j in range(3):
if trinary_number[i] == str(j):
continue
wrong_number = str(j)
changed_number = trinary_number[:i] + wrong_number + trinary_number[i + 1:]
guess_number = convert_decimal(3, changed_number)
if guess_number_list.get(guess_number):
answer = guess_number
break
print(f'#{test_case} {answer}')
๐๋ฌธ์ ํ์ธ
์ถ์ฒ: SW Expert Academy
๋ฐ์ํ
'Algorithm Problem > Python' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[python] SWEA - 12052. ๋ถ์์ง ํ์ผ (0) | 2022.03.28 |
---|---|
[python] SWEA - 4301. ์ฝฉ ๋ง์ด ์ฌ๊ธฐ (0) | 2022.03.26 |
[python] SWEA - 3347. ์ฌ๋ฆผํฝ ์ข ๋ชฉ ํฌํ (0) | 2022.03.24 |
[python] SWEA - 2805. ๋์๋ฌผ ์ํํ๊ธฐ (0) | 2022.03.23 |
[python] SWEA - 1225. [S/W ๋ฌธ์ ํด๊ฒฐ ๊ธฐ๋ณธ] 7์ผ์ฐจ - ์ํธ์์ฑ๊ธฐ (0) | 2022.03.22 |