파이썬을 파이썬 답게 1 | 프로그래머스 강의

타샤's 월드·2022년 8월 10일
0

a,b = map(int, input().split())
print(divmod(5,3))

>>(1,2)
#언패킹까지 사용
a,b = map(int, input().split())
print(*divmod(5,3))

>>1,2

n진법으로 표기된 string을 10진법 숫자로 변환하기

'''내가 푼 방식ㅜ0ㅜ'''
a,b=map(int,input().split())
A=str(a)
value=1
ls=[]
print(len(A))
for i in range(len(A)):
  print(f'{A[-1-i]}*{value}= {int(A[-1-i])*value}')
  ls.append(int(A[-1-i])*value)
  value*=b

print(sum(ls))
'''enumerate과 제곱을 적극적으로 사용하자'''
answer=0
for idx, num in enumerate(str(a)[::-1]):
  answer += int(num)*(b**idx)

print(answer)
'''int는 진법 변환을 지원한다!!!'''
a,b=input().split()
print(int(a,int(b)))

문자열 정렬하기

문자열 s와 자연수 n이 입력으로 주어집니다. 문자열 s를 좌측 / 가운데 / 우측 정렬한 길이 n인 문자열을 한 줄씩 프린트해보세요.

'''내가 쓴 식ㅜㅜ'''
s,n= input().split()
v=int(n)-len(s)  #공백문자 길이
m=v//2
print(s+(' '*v))
print((' '*m)+s+(' '*m))
print((' '*v)+s)
'''간단한 파이썬 내장함수로 다 처리 가능'''
s= '가나다라'
n=7

s.ljust(n)
s.center(n)
s.rjust(n)

알파벳 출력하기

from string import ascii_lowercase, ascii_uppercase
n=int(input())
if n==0:
  print(*list(ascii_lowercase))
if n==1:
  print(*list(ascii_uppercase))

문자열 내 마음대로 정렬하기

def solution(strings, n):
    return sorted(sorted(strings), key=lambda x :x[n])

https://ooyoung.tistory.com/59

프로그래머스 완주하지 못한 선수 Counter 사용

'''콜랙션의 카운터를 사용해보자!!!'''
from collections import Counter
def solution(part, compl):
    ans=Counter(part)-Counter(compl)
    return list(ans)[0]
    
    
    
 >>> Counter(part) = Counter({'leo': 1, 'kiki': 1, 'eden': 1})

Counter: 백준 단어 공부

from collections import Counter


st=input().upper()

counter=Counter(st).most_common()
if len(counter)>1 and counter[0][1]==counter[1][1]:
  print('?')
else:
  print(counter[0][0].upper())

프로그래머스 두 정수 사이의 합

def adder(a, b):
    # 함수를 완성하세요
    return sum(range(min(a,b),max(a,b)+1))
    
    
    '''sum(range(3,6))'''
profile
그때 그때 꽂힌것 하는 개발블로그

0개의 댓글