Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | 31 |
Tags
- 파이썬
- N과M
- 프로그래머스
- 가상메모리
- 수학
- 코딩테스트
- 힙
- dict
- 재귀
- dfs
- 그리디
- BFS
- 백준
- BOJ
- programmers
- level2
- level1
- 다이나믹 프로그래밍
- 구현
- level3
- 가상메모리 관리
- MYSQL
- 브루트포스
- 다익스트라
- DP
- level0
- 딕셔너리
- python
- 스택
- 운영체제
Archives
- Today
- Total
동캄의 코딩도장
백준 21314 [민겸 수] 파이썬 본문
https://www.acmicpc.net/problem/21314
21314번: 민겸 수
민겸 수 하나가 주어진다. 민겸 수는 대문자 M과 K로만 이루어진 문자열이며, 길이는 3,000을 넘지 않는다.
www.acmicpc.net
#백준 21314
import sys
from math import *
lst=list(map(str,sys.stdin.readline().rstrip()))
count=0
ans1=[]
ans2=[]
for i in range(len(lst)):
if lst[i]=='K':
ans1.append('5')
ans1.append('0'*count)
if count!=0:
ans2.append('1')
ans2.append('0'*(count-1))
ans2.append('5')
count=0
else:
count+=1
if count!=0:
ans1.append('1'*count)
ans2.append('1')
ans2.append('0'*(count-1))
print(''.join(ans1))
print(''.join(ans2))
그리디하게 해결하면 된다.
'코테 > BOJ' 카테고리의 다른 글
백준 14400 [편의점 2] 파이썬 (0) | 2022.09.05 |
---|---|
백준 7507 [올림픽 게임] 파이썬 (0) | 2022.09.04 |
백준 20310 [타노스] 파이썬 (0) | 2022.09.04 |
백준 20365 [블로그 2] 파이썬 (0) | 2022.09.04 |
백준 16112 [5차 전직] 파이썬 (0) | 2022.09.04 |