1217 거듭제곱
def mul(num,k):
global n,cnt
num *= n
if k == cnt:
return num
return mul(num,k+1)
for tc in range(10):
N = int(input())
n,cnt = map(int, input().split())
print("#{} {}".format(N,mul(1,1)))
또 다른 방식
def mul(n,m):
if m == 1:
return n
return mul(n,m-1)*n
for tc in range(10):
a = int(input())
b,c = map(int, input().split())
print('#{} {}'.format(a,mul(b,c)))
1230 암호문3
오래 걸리지만, 문제를 잘 이해하고 차근차근 짜면 쉽게 풀리는 문제. 심지어 맨 마지막 조건은 구현하지 않아도 통과가 되버리는 문제.
for tc in range(1,11):
N = int(input())
pw = list(map(int, input().split()))
C = int(input())
commands = list(input().split())
for i in range(len(commands)):
if commands[i] == "I":
idx = int(commands[i+1])
cnt = int(commands[i+2])
for j in range(cnt):
pw.insert(idx+j,int(commands[i+3+j]))
elif commands[i] == "D":
idx = int(commands[i+1])
cnt = int(commands[i+2])
for j in range(cnt):
del pw[idx]
elif commands[i] == "A":
cnt = int(commands[i+1])
for j in range(1,cnt+1):
pw.append(commands[i+j+1])
print("#{} {}".format(tc," ".join(map(str,pw[:10]))))
3431 준환이의 운동관리
for tc in range(int(input())):
L,U,X = map(int,input().split())
print("#{} {}".format(tc+1, -1 if X>U else(L-X if X<L else 0)))
4406 모음이 보이지 않는 사람
다양한 반법으로 풀 수 있는 문제
- 방법 1 : lambda, filter 식을 사용해서 해당되는 것들만 리스트로 만들어 묶어주는 방법
- 방법 2 : 정규표현식을 사용해 조건에 맞는 값들만 가져오는 방법(단, re 불러와야 함)
방법1 - 짧은 코드지만 가독성이 그리 좋지는 않음
for tc in range(int(input())):
s = list(input())
print("#{} {}".format(tc+1, "".join(list(filter(lambda x : x not in ["a","e","i","o","u"],s)))))
방법 2 - re불러오는 시간은 걸려도 가독성이 좋고 이해하기 쉬움
import re
for tc in range(int(input())):
s = input()
print("#{} {}".format(tc+1,re.sub('a|e|i|o|u','',s)))
# 참고 - print(s) // congratulations로 원본 그대로 유지됨
cf. 그냥 문제 조건대로 차근차근 푸는 방법도 있음
for tc in range(int(input())):
a = list(map(str,input()))
b = []
aeiou = ['a','e','i','o','u']
for alphabet in a:
if alphabet in aeiou:
continue
else:
b.append(alphabet)
print('#{} {}'.format(tc+1,''.join(b)))
'Problem Solving > SWEA' 카테고리의 다른 글
[ SWEA ] D3 - 1220, 1216, 5601, 10570 - python 문제풀이 (0) | 2021.07.01 |
---|---|
[ SWEA ] D3 - 1215, 1225, 1289, 10505 - python 문제풀이 (0) | 2021.06.30 |
[ SWEA ] D2 - 1940, 1928, 1288, 1284, 1204 - python 문제풀이 (0) | 2021.06.28 |
[ SWEA ] D2 - 1954, 1948, 1946, 1945 - python 문제풀이 (0) | 2021.06.27 |
[ SWEA ] D2 - 1970, 1966, 1961, 1959 - python 문제풀이 (0) | 2021.06.26 |
댓글