Notice
Recent Posts
Recent Comments
Link
250x250
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Flutter
- Vue
- codingtest
- DFS
- C++
- cos pro
- 코딩테스트
- DFS와BFS
- android
- Algorithm
- vuejs
- 파이썬
- cos
- 코드품앗이
- 코테
- 백준
- 동적계획법과최단거리역추적
- 동적계획법
- 분할정복
- DART
- cos pro 1급
- AndroidStudio
- BAEKJOON
- django
- Python
- 안드로이드스튜디오
- 안드로이드
- 개발
- issue
- 알고리즘
Archives
- Today
- Total
Development Artist
[COS Pro 1급, Python] 3차 5번 : 전광판 문구 출력 본문
728x90
반응형
문제 유형
코딩
난이도
normal
Note
1. 나타날때, 사라질때를 구별해서 구현. <- 이게 바로 떠올라야함.
Code 1
# -*- coding: utf-8 -*-
# UTF-8 encoding when using korean
# 3차 5번
def solution(phrases, second):
answer = ''
length = 14
step = second // length
loc = second % length
print(step, loc)
if step % 2 == 0: # 나타날 때
if loc == 0:
answer = '______________'
else:
for _ in range(length - loc):
answer += '_'
for i in range(loc):
answer += phrases[i]
print(answer)
else: # 사라질 때
if loc == 0:
answer = phrases
else:
for i in range(length - loc):
answer += phrases[i+loc]
for _ in range(loc):
answer += '_'
return answer
phrases = "happy-birthday"
second = 3
ret = solution(phrases, second)
print("solution 함수의 반환 값은", ret, "입니다.")
phrases = "happy-birthday"
second = 20
ret = solution(phrases, second)
print("solution 함수의 반환 값은", ret, "입니다.")
Code 2
def solution(phrases, second):
answer = ''
plen = len(phrases)
if plen > second:
dist = plen-second
front = ''
for _ in range(dist):
front += '_'
return front+phrases[0:second]
else:
dis = second - plen
back = ''
for _ in range(dist):
back += '_'
return phrases[dis:]+back
※ 가끔 코드 중 print(~)가 있습니다. 정리 못한 점 죄송합니다.
728x90
반응형
'Algorithm > COS' 카테고리의 다른 글
[COS Pro 1급, Python] 3차 7번 : 카프리카 수 (0) | 2022.02.25 |
---|---|
[COS Pro 1급, Python] 3차 6번 : 소수의 합으로 표현하기 (0) | 2022.02.25 |
[COS Pro 1급, Python] 3차 4번 : 중복 문자열 이어붙이기 (0) | 2022.02.25 |
[COS Pro 1급, Python] 3차 3번 : 비숍으로부터 도망쳐 (0) | 2022.02.25 |
[COS Pro 1급, Python] 3차 2번 : 팰린드롬 문제 (0) | 2022.02.25 |
Comments