~๋ชฉ์ฐจ~
์ค๋๋ง์ ๋ฌธ์ ํ์ด ๊ธ์ ์ฌ๋ฆฌ๊ฒ ๋์๋ค. ์ทจ์ค๊น์ง ๊พธ์คํ ํ์ดํ ..!
๋ฌธ์
https://softeer.ai/practice/6268
๋ฌธ์ ํด๊ฒฐ ํฌ์ธํธ
- ์ํ
- ์ ๊ดํ์ ํ์ํ ์ ์๋ ์ซ์ ๋ชจ์์ 7์๋ฆฌ์ 2์ง์๋ก ์ ํํ์ฌ ์ ์ฅ
- 7์๋ฆฌ ์์๋ ์์๋ก ์ง์
- ์ผ์ ธ์๋ค๋ฉด 1, ๊บผ์ ธ์๋ค๋ฉด 0
ex) 0 -> 1,1,1,0,1,1,1
- ์๋ฆฟ์๊ฐ ๋ง์ง ์๋๋ค๋ฉด ๊ณต๋ฐฑ์ผ๋ก ์ฑ์์ ๋ค์ฏ์๋ฆฟ์๋ฅผ ๋ง์ถ๋ค.
ex) 9012 -> 09012
์์ฑ ์ฝ๋
1) ์ค์ค๋ก ์์ฑํ ์ฝ๋
import sys
input = sys.stdin.readline
number = [[1,1,1,0,1,1,1], [0,0,1,0,0,0,1], [0,1,1,1,1,1,0], [0,1,1,1,0,1,1],
[1,0,1,1,0,0,1], [1,1,0,1,0,1,1], [1,1,0,1,1,1,1], [1,1,1,0,0,0,1],
[1,1,1,1,1,1,1], [1,1,1,1,0,1,1]]
def checkDiff(a, b):
result = 0
alist = number[int(a)]
blist = number[int(b)]
for i in range(7):
if alist[i] != blist[i]:
result += 1
return result
def diffLen(minvalue, maxvalue, minlen, maxlen):
result = 0
# ๋์น๋ ์๋ฆฟ ์ ๊ตฌ๋ถ
maxfront = maxvalue[:maxlen-minlen]
maxback = maxvalue[maxlen-minlen:]
# ๋์น๋ ์๋ฆฌ ์ ๋ชจ๋ ๋๊ธฐ
for i in maxfront:
result += sum(number[int(i)])
# ๊ฐ ์๋ฆฌ ์ ๋ณ ์ฒดํฌ
for i in range(minlen):
result += checkDiff(minvalue[i], maxback[i])
return result
for _ in range(int(input())):
a, b = input().split()
alen, blen = len(a), len(b)
result = 0
if alen == blen:
for i in range(alen):
result += checkDiff(a[i], b[i])
elif alen < blen:
result = diffLen(a, b, alen, blen)
else:
result = diffLen(b, a, blen, alen)
print(result)
2) ์ฐธ๊ณ ํ์ฌ ์์ ํ ์ฝ๋
import sys
input = sys.stdin.readline
number = {
'0' : [1,1,1,0,1,1,1],
'1' : [0,0,1,0,0,0,1],
'2' : [0,1,1,1,1,1,0],
'3' : [0,1,1,1,0,1,1],
'4' : [1,0,1,1,0,0,1],
'5' : [1,1,0,1,0,1,1],
'6' : [1,1,0,1,1,1,1],
'7' : [1,1,1,0,0,0,1],
'8' : [1,1,1,1,1,1,1],
'9' : [1,1,1,1,0,1,1],
' ' : [0,0,0,0,0,0,0]
}
# ๋๋ฌ์ผํ๋ ๋ฒํผ ๊ฐ์ ๊ตฌํ๊ธฐ
def checkDiff(a, b):
result = 0
for i in range(5):
# ์ซ์ ๋ชจ์์ ๋ง๋ ๋ฆฌ์คํธ
tmpa, tmpb = number[a[i]], number[b[a]]
for j in range(7):
if tmpa[j] != tmpb[j]:
result += 1
return result
# Test ์์
for _ in range(int(input())):
a, b = input().split()
# ๋ชจ๋ ๊บผ์ง ๊ฒ์ ' '(๊ณต๋ฐฑ), ๊ธธ์ด๋ฅผ ๋ชจ๋ 5๋ก ๋ง์ถ๊ธฐ
a = ' '*(5-len(a)) + a
b = ' '*(5-len(b)) + b
print(checkDiff(a, b))
๋์์ด ๋์ จ๋ค๋ฉด ์ข์์ ๋๋ฌ์ฃผ์ธ์๐
REFERENCE
https://jie0025.tistory.com/427
'๐๋ฌธ์ ํ์ด > ๐งฉSofteer' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Python] Softeer ์๋์ฐจ ํ ์คํธ - ์ ๋ ฌ (2) | 2024.08.31 |
---|---|
[Python] [HSAT 7ํ ์ ๊ธฐ ์ฝ๋ฉ ์ธ์ฆํ๊ฐ ๊ธฐ์ถ] ์์๋๋ก ๋ฐฉ๋ฌธํ๊ธฐ (0) | 2024.08.28 |