728x90
반응형

단순 구현 문제이다. 딕셔너리와 리스트를 사용해서 두 가지 방식으로 풀어봤다. 

첫 번째 코드가 더 보기 좋은 것 같긴 하다.

s1, s2, s3 = map(int, input().split())
li = [0]*81
for i in range(1, s1+1):
    for j in range(1, s2+1):
        for k in range(1, s3+1):
            li[i+j+k] += 1
print(li.index(max(li)))
s1, s2, s3 = map(int, input().split())
d = {}
for i in range(1, s1+1):
    for j in range(1, s2+1):
        for k in range(1, s3+1):
            d[i+j+k] = d.get(i+j+k, 0) + 1
li = sorted(d.items(), key=lambda x:x[0])
li = sorted(li, key=lambda x:x[1], reverse=True)
print(li[0][0])
728x90
반응형
728x90
반응형

단순 문자열 문제이다. Python3로 제출하면 시간 초과가 나와서 PyPy3로 제출했다.

a, b = input().split()
res = 0
for n1 in a:
    for n2 in b:
        res += int(n1)*int(n2)
print(res)
728x90
반응형
728x90
반응형

단순 구현 문제이다. 운동을 끝내지 못할 때만 주의해주면 된다 -> m+T > N인 경우

N, m, M, T, R = map(int, input().split())
cnt = t = 0
now = m
while cnt < N:
    if m+T > M:
        break
    if now + T <= M:
        now += T
        cnt += 1
    else:
        now = max(now-R, m)
    t += 1
print(t if cnt == N else -1)
728x90
반응형
728x90
반응형

단순 문자열 문제이다. 

li = sorted([input()[0] for _ in range(int(input()))])
s = set(li)
res = []
for c in s:
    if li.count(c) >= 5:
        res.append(c)
print(''.join(sorted(res)) if len(res) > 0 else "PREDAJA")
728x90
반응형
728x90
반응형

정렬 몇 번만 해주면 쉽게 풀 수 있는 문제이다.

li = [int(input()) for _ in range(8)]
sorted_li = sorted(li, reverse=True)
t = sum(sorted_li[:5])
idx_li = sorted([li.index(sorted_li[i])+1 for i in range(5)])
print(t)
print(*idx_li)

 

728x90
반응형
728x90
반응형

문제 주소: codeforces.com/problemset/problem/69/A

단순한 사칙연산 문제이다.

x = y = z = 0
for _ in range(int(input())):
    a, b, c = map(int, input().split())
    x += a; y += b; z += c
print("YES" if x == y == z == 0 else "NO")
728x90
반응형

'Agorithm > Codeforces' 카테고리의 다른 글

96A-Football  (0) 2021.02.16
236A-Boy or Girl  (0) 2021.02.16
281A-Word Capitalization  (0) 2021.02.16
339A-Helpful Maths  (0) 2021.02.16
263A-Beautiful Matrix  (0) 2021.02.16
728x90
반응형

문제 주소: codeforces.com/problemset/problem/96/A

간단한 문자열 문제이다.

"0000000" 또는 "1111111" 이 문자열안에 들어있으면 YES 아니면 NO를 출력해주면 된다.

s = input()
if '0'*7 in s or '1'*7 in s:
    print("YES")
else:
    print("NO")
728x90
반응형

'Agorithm > Codeforces' 카테고리의 다른 글

69A-Young Physicist  (0) 2021.02.16
236A-Boy or Girl  (0) 2021.02.16
281A-Word Capitalization  (0) 2021.02.16
339A-Helpful Maths  (0) 2021.02.16
263A-Beautiful Matrix  (0) 2021.02.16
728x90
반응형

문제 주소: codeforces.com/problemset/problem/236/A

문자열의 길이가 아니라 문자열에 몇 종류의 문자가 있는지를 알아야 해서 set을 사용해줬다.

s = set(input())
print("IGNORE HIM!" if len(s)%2 else "CHAT WITH HER!")
728x90
반응형

'Agorithm > Codeforces' 카테고리의 다른 글

69A-Young Physicist  (0) 2021.02.16
96A-Football  (0) 2021.02.16
281A-Word Capitalization  (0) 2021.02.16
339A-Helpful Maths  (0) 2021.02.16
263A-Beautiful Matrix  (0) 2021.02.16
728x90
반응형

문제 주소: codeforces.com/problemset/problem/281/A

문자열은 불변이기에 리스트로 바꿔서 처리해줬다. 

join함수를 사용하면 리스트의 문자열들을 합칠 수 있다.

li = list(input())
if 'a' <= li[0] <= 'z':
    li[0] = li[0].upper()
print(''.join(li))
728x90
반응형

'Agorithm > Codeforces' 카테고리의 다른 글

96A-Football  (0) 2021.02.16
236A-Boy or Girl  (0) 2021.02.16
339A-Helpful Maths  (0) 2021.02.16
263A-Beautiful Matrix  (0) 2021.02.16
112A-Petya and Strings  (0) 2021.02.16
728x90
반응형

문제 주소: codeforces.com/problemset/problem/339/A

파이썬의 꼼수(잡기술)를 좀 사용해봤다. 

li = sorted(list(map(int, input().split('+'))))
print(*li, sep='+')

파이썬에서 *은 컨테이너 타입의 데이터를 Unpacking 해준다.

EX) *[1, 2, 3] -> 1, 2, 3

print 함수에서 sep를 사용하면 print문의 출력문들 사이에 해당하는 문자를 넣을 수 있다.

EX) print(1, 2, 3, sep='A') -> 1A2A3

728x90
반응형

'Agorithm > Codeforces' 카테고리의 다른 글

236A-Boy or Girl  (0) 2021.02.16
281A-Word Capitalization  (0) 2021.02.16
263A-Beautiful Matrix  (0) 2021.02.16
112A-Petya and Strings  (0) 2021.02.16
282A-Bit++  (0) 2021.02.16
728x90
반응형

문제 주소: codeforces.com/problemset/problem/263/A

1의 위치만 알면 쉽게 풀 수 있는 간단한 2차원 배열 문제이다.

li = [list(map(int, input().split())) for _ in range(5)]
for i in range(5):
    for j in range(5):
        if li[i][j] == 1:
            x, y = i, j
            break
print(abs(x-2) + abs(y-2))
728x90
반응형

'Agorithm > Codeforces' 카테고리의 다른 글

281A-Word Capitalization  (0) 2021.02.16
339A-Helpful Maths  (0) 2021.02.16
112A-Petya and Strings  (0) 2021.02.16
282A-Bit++  (0) 2021.02.16
118A-String Task  (0) 2021.02.16
728x90
반응형

문제 주소: codeforces.com/problemset/problem/112/A

간단한 문자열 문제이다.

파이썬은 별도의 함수를 사용하지 않아도 문자열 비교가 바로바로 되어서 참 편한 것 같다.

s1 = input().lower()
s2 = input().lower()
if s1 == s2:
    print(0)
elif s1 < s2:
    print(-1)
else:
    print(1)
728x90
반응형

'Agorithm > Codeforces' 카테고리의 다른 글

339A-Helpful Maths  (0) 2021.02.16
263A-Beautiful Matrix  (0) 2021.02.16
282A-Bit++  (0) 2021.02.16
118A-String Task  (0) 2021.02.16
50A-Domino piling  (0) 2021.02.16
728x90
반응형

문제 주소: codeforces.com/problemset/problem/282/A

간단한 문자열 문제이다. in을 사용해서 풀었다.

x = 0
for _ in range(int(input())):
    s = input()
    if "++" in s:
        x += 1
    elif "--" in s:
        x -= 1
print(x)
728x90
반응형

'Agorithm > Codeforces' 카테고리의 다른 글

263A-Beautiful Matrix  (0) 2021.02.16
112A-Petya and Strings  (0) 2021.02.16
118A-String Task  (0) 2021.02.16
50A-Domino piling  (0) 2021.02.16
158A-Next Round  (0) 2021.02.16
728x90
반응형

문제 주소: codeforces.com/problemset/problem/118/A

간단한 문자열 관련 문제이다. 둘다 맞는 코드이긴 한데 더 좋은 방법이 있을 거 같다.

s = input().lower()
for c in s:
    if c in "aoyeui":
        continue
    print(f".{c}", end='')
print()
s = input().lower()
res = ''
for c in s:
    if c in "aoyeui":
        continue
    res += f".{c}"
print(res)
728x90
반응형

'Agorithm > Codeforces' 카테고리의 다른 글

112A-Petya and Strings  (0) 2021.02.16
282A-Bit++  (0) 2021.02.16
50A-Domino piling  (0) 2021.02.16
158A-Next Round  (0) 2021.02.16
231A-Team  (0) 2021.02.16
728x90
반응형

문제 주소: codeforces.com/problemset/problem/50/A

처음엔 아래 코드 같이 생각했다. 

M, N = map(int, input().split())
print(M//2 * N + (N//2 if M%2 else 0))

근데 잘 생각해보니 도미노를 못 채우는 공간은 어떤 경우든 항상 마지막 줄 마지막 한 칸이다.

못 채우는 공간이 존재하더라도 그건 딱 "한 칸"이라는 것이다.

따라서 M*N(넓이)에 2를 나눈 값을 내림해준 결과가 정답이 된다. -> M*N//2

M, N = map(int, input().split())
print(M*N//2)
728x90
반응형

'Agorithm > Codeforces' 카테고리의 다른 글

282A-Bit++  (0) 2021.02.16
118A-String Task  (0) 2021.02.16
158A-Next Round  (0) 2021.02.16
231A-Team  (0) 2021.02.16
1A-Theatre Square  (0) 2021.02.16

+ Recent posts