백준 브론즈 2 모음
https://www.acmicpc.net/problem/2798
import itertools
a,b = map(int,input().split())
l = sorted(map(int,input().split()))
r=[]
for i in itertools.combinations(l,3):
r.append(sum(i))
new = max([x for x in r if x<=b])
print(new)
입력받는 건 나의 몫! 나머지는~ 역시 map함수군.. map은 각 원소 별로 콜백함수를 실행하는 것인가? map(int,list)는 int()를 각 원소마다 실행하기!
print(max(x for x in map(sum,combinations(l,3))if x<=m))
근데 얘가 itertools를 쓰네? 시간초과는 언제 나는 거지?
이 밑은 코테 적응 전! 앞으로 맨 위에다가 최신 풀이 작성할 것.
https://www.acmicpc.net/problem/1712
a,b,c = map(int,input().split())
if(c<=b or a//(c-b)<0):
print(-1)
else:
print(a//(c-b) + 1)
음 저 조건은 아예 불필요한가
a,b,c = map(int, input().split())
if b >= c:
print(-1)
else:
print(a//(c-b)+1)
https://www.acmicpc.net/problem/2577
a,b,c = map(int,open(0))
cnt = [0,0,0,0,0,0,0,0,0,0]
res = str(a*b*c)
for i in res:
cnt[int(i)] += 1
for i in cnt:
print(i)
뭘까 이 코드... ?
n=1
for i in range(3):
n*=int(input())
for i in range(10):
print(str(n).count(str(i))) // 이거 이해하기
// 문자열.count(찾을 문자열) -> 개수 나옴
https://www.acmicpc.net/problem/1152
s = input().split()
print(len(s))
이것도 되는군
print(len(input().split()))
https://www.acmicpc.net/problem/2908
a,b = input().split()
print(max(int(a[::-1]),int(b[::-1])))
https://www.acmicpc.net/problem/1977
import math
a,b = map(int,open(0))
a = math.ceil(math.sqrt(a))
b = int(math.sqrt(b))
sum = 0
for i in range(a,b+1):
sum += i**2
if sum>0:
print(sum)
print(a**2)
else:
print(-1)
https://www.acmicpc.net/problem/8958
a = int(input())
for _ in range(a):
s = input().split('X')
sum = 0
for i in s:
n = len(i)
if(n>0):
sum += int(n*(n+1)/2)
print(sum)
if를 안 했어도 됐네. 어차피 0 나오는데 더해도 상관없지
n=int(input())
for i in range(n):
N=0
L=input().split('X')
for j in L:
k=len(j)
N+=(k*(k+1))/2
print(int(N))
https://www.acmicpc.net/problem/2920
l = list(map(int,input().split()))
a = sorted(l)
d = sorted(l,reverse=True)
if(l == a):
print('ascending')
elif(l == d):
print('descending')
else:
print('mixed')
이렇게 그냥 하드코딩해도 되는군... 코테의 세계란....
n = input()
if n == '1 2 3 4 5 6 7 8':
print('ascending')
elif n == '8 7 6 5 4 3 2 1':
print('descending')
else:
print('mixed')
https://www.acmicpc.net/problem/3052
l = map(int,open(0))
s = set([])
for i in l:
s.add(i % 42)
print(len(s))
여러 개행을 리스트로 입력 받기 l = map(int,open(0))
https://www.acmicpc.net/problem/15596
def solve(a):
ans = 0
for i in a:
ans += i
return ans
ㄷㅂ 이게 되네 오... 신기하구먼
solve=sum
https://www.acmicpc.net/problem/2750
n = int(input())
l = []
for _ in range(n):
l.append(int(input()))
l.sort()
for i in l:
print(i)
https://www.acmicpc.net/problem/2231
아 이거 음.. 풀었는데 분해합 생성자가 없는 경우를 못 골라내겠음
str_n = input()
num_n = int(str_n)
a = num_n-len(str_n)*9
for i in range(a,num_n+1):
str_i = str(i)
sum = i
for j in str_i:
sum += int(j)
if(sum == num_n):
print(i)
break
내 코드에서 수정을 해봤는데... 음 :(
str_n = input()
num_n = int(str_n)
res = 0 # 여기
for i in range(1,num_n+1): # 여기
str_i = str(i)
sum = i
for j in str_i:
sum += int(j)
if(sum == num_n):
res = i
# print(i) # 여기
break
print(res) # 여기 수정함
정말 모르겠군 지금이 고비인가
N = int(input())
result = 0
for i in range(1, N + 1):
tmp = i + sum(map(int,str(i)))
if tmp == N:
result = i
break
print(result)
https://www.acmicpc.net/problem/5622
ㅋㅋㅋ 이런 코드 오랜만이군... 모든 분기처리 다 하기...
s = input()
sum = 0
for i in s:
i = ord(i) - 65
if i == 18:
sum += 8
elif 18 < i < 22:
sum += 9
elif i >= 22:
sum += 10
else:
sum += i//3 + 3
print(sum)
이건 그냥 다 써야하는구나...
alph = "22233344455566677778889999"
num = 0
for i in input():
num += int(alph[ord(i)-65]) + 1
print(num)
https://www.acmicpc.net/problem/1225
아 이거 ㅋㅋㅋ 조금만 더 생각해볼 걸 숫자로 예제가 나와있어서 좀 헤맴
a,b = input().split()
sum = res = 0
for i in a:
sum += int(i)
for i in b:
res += sum * int(i)
print(res)
map(콜백,리스트) 하면 반환값이 리스트인가? ㄹㅈㄷ
a,b = input().split()
sum_a = sum(map(int,a))
sum_b = sum(map(int,b))
print(sum_a * sum_b)
https://www.acmicpc.net/problem/7567
p = ''
res = 0
for i in input():
if i == p:
res += 5
else:
res += 10
p = i
print(res)
https://www.acmicpc.net/problem/1009
나는 시간초과가 나면 바로 답지를 본다. 시간초과는 내가 해결할 수 있는 영역이 아님. 나의 시간초과 코드~
n = int(input())
for _ in range(n):
a,b = map(int,input().split())
res = (a**b) % 10
print(10 if res == 0 else res)
https://www.acmicpc.net/problem/2747
재귀로 하면 시간초과 날 것 같아서 바꿈
n = int(input())
res = [0,1,1]
if n == 0:
print(0)
elif n == 1 or n == 2:
print(1)
else:
for i in range(n-2):
res.append(res[i+1]+res[i+2])
print(res[n])
def fibo(n):
if n == 0:
return 0
elif n == 1 or n == 2:
return 1
else:
return fibo(n-1) + fibo(n-2)
n = int(input())
print(fibo(n))
https://www.acmicpc.net/problem/1075
요즘은 내 풀이에 확신이 있으면 다른 사람 코드를 안 보는 것 같다. 특히 숏코딩...
# a,b = map(int,open(0))
a = int(input())
b = int(input())
r = a%100
for i in range(a-r,a+b):
if i % b == 0:
print(str(i)[-2:])
break
https://www.acmicpc.net/problem/1357
a,b = input().split()
res = int(a[::-1]) + int(b[::-1])
res = str(res)[::-1]
print(int(res))
https://www.acmicpc.net/problem/2355
a,b = map(int,input().split())
x = max(a,b)
y = min(a,b)
print(int((x+y)*(x-y+1)/2))