https://www.acmicpc.net/problem/1541
1541๋ฒ: ์์ด๋ฒ๋ฆฐ ๊ดํธ
์ฒซ์งธ ์ค์ ์์ด ์ฃผ์ด์ง๋ค. ์์ ‘0’~‘9’, ‘+’, ๊ทธ๋ฆฌ๊ณ ‘-’๋ง์ผ๋ก ์ด๋ฃจ์ด์ ธ ์๊ณ , ๊ฐ์ฅ ์ฒ์๊ณผ ๋ง์ง๋ง ๋ฌธ์๋ ์ซ์์ด๋ค. ๊ทธ๋ฆฌ๊ณ ์ฐ์ํด์ ๋ ๊ฐ ์ด์์ ์ฐ์ฐ์๊ฐ ๋ํ๋์ง ์๊ณ , 5์๋ฆฌ๋ณด๋ค
www.acmicpc.net
s = input()
s = s.split('-')
s2 = []
res = 0
if s[0].isdigit():
res += int(s[0])
else:
s2 = s[0].split('+')
for i in s2:
res += int(i)
del s[0]
for i in s:
if i.isdigit():
res -= int(i)
else:
s2.clear()
s2 = list(map(int, i.split('+')))
res -= sum(s2)
print(res)
๋ง๊ธด ๋ง์๋๋ฐ,,, ์ฝ๋๊ฐ ์ด๋ง๋ฌด์ํ๊ฒ ๊ธธ์ด์,, ๋ค์ ๋ค๋ฌ์ด๋ดค๋ค,,
s = input().split('-')
res = 0
for i in range(len(s)):
for j in s[i].split('+'):
if i == 0:
res += int(j)
else:
res -= int(j)
print(res)
๋ค์ ์๊ฐํด๋ณด๋ ๊ตณ์ด ์ซ์๋๊ณ ๋ฌป์ง ์์๋ ๋์,,,
๋์ ์ํ์ฐฉ์ค ใ ใ
'๐ค > ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๋ฐฑ์ค 5585: ๊ฑฐ์ค๋ฆ๋ (Python) (0) | 2021.09.29 |
---|---|
๋ฐฑ์ค 1026: ๋ณด๋ฌผ (Python) (0) | 2021.09.29 |
๋ฐฑ์ค 1931: ํ์์ค ๋ฐฐ์ (Python) (0) | 2021.09.27 |
๋ฐฑ์ค 11047: ๋์ 0 (Python) (0) | 2021.09.25 |
๋ฐฑ์ค 11399: ATM (Python) (0) | 2021.09.25 |