문제
17413번: 단어 뒤집기 2
문자열 S가 주어졌을 때, 이 문자열에서 단어만 뒤집으려고 한다. 먼저, 문자열 S는 아래와과 같은 규칙을 지킨다. 알파벳 소문자('a'-'z'), 숫자('0'-'9'), 공백(' '), 특수 문자('<', '>')로만 이루어져
www.acmicpc.net
알고리즘
- 입력에 따라 명령을 수행한다.
코드
import sys
s = list(map(str, sys.stdin.readline().strip()))
res = ""
word = ""
reverse = True
for c in s:
if c == '<':
reverse = False
res += word
word = c
elif c == '>':
reverse = True
res += (word + '>')
word = ""
elif c == ' ':
res += word + c
word = ""
elif reverse:
word = c + word
else:
word += c
res += word
print(res)
github
GitHub - junjange/CodingTest: 내가 푼 코딩 테스트 문제와 해결법
내가 푼 코딩 테스트 문제와 해결법. Contribute to junjange/CodingTest development by creating an account on GitHub.
github.com
'CodingTest > Baekjoon' 카테고리의 다른 글
[baekjoon] 백준 10951번(파이썬): A+B - 4 (0) | 2021.09.07 |
---|---|
[baekjoon] 백준 1110번(파이썬): 더하기 사이클 (0) | 2021.09.07 |
[baekjoon] 백준 10866번(파이썬): 덱 (0) | 2021.09.06 |
[baekjoon] 백준 1158번(파이썬): 요세푸스 문제 (0) | 2021.09.06 |
[baekjoon] 백준 10845번(파이썬): 큐 (0) | 2021.09.06 |