Tags
- ์๋ฎฌ๋ ์ด์
- ์๋ฃ๊ตฌ์กฐ
- BOJ
- ๋ฌธ์์ด
- DP
- greedy
- BFS
- LV2
- ๊ทธ๋ํ ์ด๋ก
- ๊น์ด ์ฐ์ ํ์
- ๋ฐฑํธ๋ํน
- stack
- SpringBoot
- dfs
- ์ ์๋ก
- Python
- Java
- ๊ทธ๋ํ ํ์
- PGM
- CodingTest
- Brute Force Algorithm
- ๊ตฌํ
- ๊ต์ฌ
- Study
- ์ ๋ ฌ
- ์ํ
- queue
- sort
- Dynamic Programming
- ๋๋น ์ฐ์ ํ์
Archives
๊ธฐ๋ก๋ฐฉ
BOJ_17413 : ๋จ์ด ๋ค์ง๊ธฐ 2 ๋ณธ๋ฌธ
๐ธ ๋ฌธ์ ๋ถ์ ๐ธ
- ์ ๋ ฅ๋ ํ ์ค์ ๋ฌธ์ฅ์ ๋ค์ง์ด ์ถ๋ ฅํ๋ ๋ฌธ์ ์ด๋ค.
- <>๊ธฐํธ๋ก ๊ฐ์ธ์ง ๋ถ๋ถ์ 'ํ๊ทธ'์ด๋ฉฐ ๋ค์ง์ง ์๋๋ค.
- ๊ณต๋ฐฑ์ ๊ตฌ๋ถํด ํ ๋จ์ด์ฉ ๋ค์ง๋๋ค.
๐ธ ์ฝ๋ ๐ธ
import sys
str = sys.stdin.readline().rstrip()
tag = False
answer = ""
temp = ""
for c in str :
if c == '<':
tag = True
answer += temp[::-1]
temp = ""
answer += c
elif c == '>':
tag = False
answer += c
elif c == ' ':
answer += temp[::-1]
temp = ""
answer += ' '
elif tag :
answer += c
else :
temp += c
if temp != "":
answer += temp[::-1]
sys.stdout.write(answer)
๐ธ ์ฝ๋ ํด์ ๐ธ
- ๋น ๋ฅธ ์
์ถ๋ ฅ์ ์ํด sys.stdout.write() ์ sys.stdin.readline() ์ ์ฌ์ฉํ๊ณ ,
์ ๋ ฅ์ ๋ง์ง๋ง ์ค๋ฐ๊ฟ ๋ฌธ์ '\n'์ ์ ๊ฑฐํ๊ธฐ ์ํด rstrip()์ ๋ถ์๋ค.- tag : ํ์ฌ ํ๊ทธ ์ํ์ธ์ง ๊ตฌ๋ถ
- answer : ์ต์ข ์ถ๋ ฅ ํ ๋ฌธ์์ด
- temp : ๋ค์ง์ ๋จ์ด
- ๋จ์ด ๋ค์ง๊ธฐ๋ ๋ฌธ์์ด ์ฌ๋ผ์ด์ค [::-1]๋ฅผ ์ด์ฉํ๋ค.
๐ธ end ๐ธ
- ๋ฌธ์ ์ ๊ตฌํ์ ๊ฐ๋จํ๊ณ , ๋น ๋ฅธ ์ ์ถ๋ ฅ ์ฌ์ฉ์ ์ฐ์ตํด๋ณด์๋ค.
- ๋ค์ง๋ ๋ฐฉ์์ผ๋ก ์คํ ์ฌ์ฉ์ ์๊ฐํ์ง๋ง, ์ฌ๋ผ์ด์ค๊ฐ ๋ ๊ฐ๋จํด ๋ณด์๋ค.
728x90
'CodingTest > Python' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
BOJ_2775 : ๋ถ๋ ํ์ฅ์ด ๋ ํ ์ผ (0) | 2022.08.07 |
---|---|
BOJ_2751 : ์ ์ ๋ ฌํ๊ธฐ 2 (0) | 2022.08.02 |
BOJ_10828 : ์คํ (0) | 2022.07.30 |
BOJ_20207 : ๋ฌ๋ ฅ (0) | 2022.07.21 |
BOJ_12933 : ์ค๋ฆฌ (0) | 2022.07.21 |