Sum (1209)
for _ in range(1, 11):
test_case = int(input())
array = [list(map(int, input().split())) for _ in range(100)]
answer = 0
for i in range(100):
temp = 0
for j in range(100):
temp += array[i][j]
answer = max(answer, temp)
for i in range(100):
temp = 0
for j in range(100):
temp += array[j][i]
answer = max(answer, temp)
temp = 0
for i in range(100):
temp += array[i][i]
answer = max(answer, temp)
print(f"#{test_case} {answer}")
String (1213)
for _ in range(1, 11):
test_case = int(input())
target = input()
sentence = input()
print(f"#{test_case} {sentence.count(target)}")
회문1 (1215)
def find_palindrome(array):
result = 0
for line in array:
for i in range(8 - n + 1):
target = line[i:i+n]
if target == target[::-1]:
result += 1
return result
for test_case in range(1, 11):
n = int(input())
board = [list(input().strip()) for _ in range(8)]
answer = find_palindrome(board)
board = list(zip(*board[::-1]))
answer += find_palindrome(board)
print(f"#{test_case} {answer}")
비밀번호 (1234)
for test_case in range(1, 11):
n, s = input().split()
stack = [s[0]]
for i in range(1, int(n)):
if len(stack) != 0 and stack[-1] == s[i]:
stack.pop()
else:
stack.append(s[i])
print(f"#{test_case} {''.join(map(str, stack))}")
진기의 최고급 붕어빵 (1860)
T = int(input())
for test_case in range(1, T + 1):
n, m, k = map(int, input().split())
times = sorted(list(map(int, input().split())))
bread = 0
flag = True
idx = 0
for i in range(0, times[-1] + 1):
if i > 0 and i % m == 0:
bread += k
if times[idx] <= i: # 손님 도착 시간이 되면
if bread > 0:
bread -= 1
idx += 1
else:
flag = False
break
if flag:
print(f"#{test_case} Possible")
else:
print(f"#{test_case} Impossible")
농작물 수확하기 (2805)
T = int(input())
for test_case in range(1, T + 1):
n = int(input())
board = [list(map(int, input().strip())) for _ in range(n)]
answer = 0
count = 0
for i in range(n):
gap = abs(n // 2 - i)
answer += sum(board[i][gap:n - gap])
print(f"#{test_case} {answer}")
부분 수열의 합 (2817)
from itertools import combinations
T = int(input())
for test_case in range(1, T + 1):
n, k = map(int, input().split())
numbers = list(map(int, input().split()))
answer = 0
for i in range(1, n + 1):
for combi in combinations(numbers, i):
if sum(combi) == k:
answer += 1
print(f"#{test_case} {answer}")
영준이와 신비한 뿔의 숲 (3142)
T = int(input())
for test_case in range(1, T + 1):
n, m = map(int, input().split())
animal = [0, 0] # 유니콘, 트윈혼
animal[1] = n // 2
animal[0] = n - (2 * animal[1])
while sum(animal) != m:
if sum(animal) > m:
animal[0] -= 2
animal[1] += 1
else:
animal[0] += 2
animal[1] -= 1
print(f"#{test_case}", *animal)
두 수의 덧셈 (3260)
T = int(input())
for test_case in range(1, T + 1):
a, b = map(int, input().split())
print(f"#{test_case} {a + b}")
보충학습과 평균 (3314)
T = int(input())
for test_case in range(1, T + 1):
scores = list(map(int, input().split()))
total = 0
for score in scores:
total += max(40, score)
print(f"#{test_case} {total // 5}")
준환이의 운동관리 (3431)
T = int(input())
for test_case in range(1, T + 1):
l, u, x = map(int, input().split())
answer = 0
if x < l:
answer = l - x
elif x > u:
answer = -1
print(f"#{test_case} {answer}")
직사각형 길이 찾기 (3456)
from collections import Counter
T = int(input())
for test_case in range(1, T + 1):
a, b, c = map(int, input().split())
counter = Counter((a, b, c)).most_common(2)
most = sorted(counter, key=lambda x: x[1])
print(f"#{test_case} {most[0][0]}")
퍼펙트 셔플 (3499)
T = int(input())
for test_case in range(1, T + 1):
n = int(input())
cards = list(input().split())
mark = n // 2 + n % 2
answer = []
for i in range(n // 2):
answer.append(cards[i])
answer.append(cards[i + mark])
if n % 2 == 1:
answer.append(cards[n // 2])
print(f"#{test_case} {' '.join(map(str, answer))}")
Digit sum (3750)
T = int(input())
answer = []
for _ in range(T):
n = input()
while len(n) > 1:
n = str(sum(map(int, n)))
answer.append(n)
for i in range(T):
print(f"#{i + 1} {answer[i]}")
승률 비교하기 (3975)
T = int(input())
answer = []
for _ in range(T):
a, b, c, d = map(int, input().split())
alice = a / b * 100
bob = c / d * 100
result = ''
if alice > bob:
result += "ALICE"
elif alice < bob:
result += "BOB"
else:
result += "DRAW"
answer.append(result)
for i in range(T):
print(f"#{i + 1} {answer[i]}")
영준이의 카드 카운팅 (4047)
T = int(input())
for test_case in range(1, T + 1):
cards = {'S': [], 'D': [], 'H': [], 'C': []}
current = input()
flag = True
for i in range(0, len(current), 3):
card = current[i:i + 3]
cards[card[0]].append(int(card[1:]))
for i in cards:
if cards[i] != list(set(cards[i])):
flag = False
print(f"#{test_case}", end=' ')
if not flag:
print("ERROR")
else:
for i in cards:
print(13 - len(cards[i]), end=' ')
print()
태혁이의 사랑은 타이밍 (4299)
T = int(input())
for test_case in range(1, T + 1):
d, h, m = map(int, input().split())
day = d - 11
hour = h - 11
minute = m - 11
if minute < 0:
hour -= 1
minute += 60
if hour < 0:
day -= 1
hour += 24
if day >= 0:
print(f"#{test_case} {day * 24 * 60 + hour * 60 + minute}")
else:
print(f"#{test_case} -1")
모음이 보이지 않는 사람 (4406)
T = int(input())
for test_case in range(1, T + 1):
word = input()
answer = ''
for w in word:
if w not in ['a', 'e', 'i', 'o', 'u']:
answer += w
print(f"#{test_case} {answer}")
최대 성적표 만들기 (4466)
T = int(input())
for test_case in range(1, T + 1):
n, k = map(int, input().split())
scores = list(map(int, input().split()))
scores.sort(reverse=True)
answer = 0
for i in range(k):
answer += scores[i]
print(f"#{test_case} {answer}")
늘어지는 소리 만들기 (4676)
T = int(input())
for test_case in range(1, T + 1):
s = input()
hyphen = int(input())
position = list(map(int, input().split()))
new = [[] for _ in range(len(s) + 1)]
for i in range(len(s)):
new[i + 1].append(s[i])
for p in position:
new[p].append('-')
answer = ''
for i in new:
answer += ''.join(map(str, i))
print(f"#{test_case} {answer}")
두 가지 빵의 딜레마 (5162)
T = int(input())
for test_case in range(1, T + 1):
a, b, c = map(int, input().split())
answer = c // min(a, b)
print(f"#{test_case} {answer}")
민석이의 과제 체크하기 (5431)
T = int(input())
for test_case in range(1, T + 1):
n, k = map(int, input().split())
students = [0] * (n + 1)
homework = list(map(int, input().split()))
for h in homework:
students[h] += 1
print(f"#{test_case}", end=' ')
for idx in range(1, n + 1):
if students[idx] == 0:
print(idx, end=' ')
print()
홀수일까 짝수일까 (5549)
T = int(input())
for test_case in range(1, T + 1):
n = int(input())
if n % 2 == 0:
print(f'#{test_case}', "Even")
else:
print(f'#{test_case}', "Odd")
현주의 상자 바꾸기 (5789)
T = int(input())
for test_case in range(1, T + 1):
n, q = map(int, input().split())
answer = [0] * (n + 1)
for i in range(1, q + 1):
l, r = map(int, input().split())
for j in range(l, r + 1):
answer[j] = i
print(f"#{test_case}", end=' ')
print(*answer[1:])
새샘이의 7-3-5 게임 (5948)
from itertools import combinations
T = int(input())
for test_case in range(1, T + 1):
numbers = list(map(int, input().split()))
answer = []
for combi in list(combinations(numbers, 3)):
answer.append(sum(combi))
answer = sorted(set(answer), reverse=True)
print(f"#{test_case} {answer[4]}")
다솔이의 월급 상자 (6692)
T = int(input())
for test_case in range(1, T + 1):
n = int(input())
answer = 0
for _ in range(n):
p, x = input().split()
answer += float(p) * int(x)
print(f"#{test_case} {answer:.6f}")
구독자 전쟁 (10200)
T = int(input())
for test_case in range(1, T + 1):
n, a, b = map(int, input().split())
print(f"#{test_case} {min(a, b)} {max(0, a + b - n)}")
소득 불균형 (10505)
T = int(input())
for test_case in range(1, T + 1):
n = int(input())
data = list(map(int, input().split()))
avg = sum(data) // n
answer = 0
for d in data:
if d <= avg:
answer += 1
print(f"#{test_case} {answer}")
제곱 팰린드롬 수 (10570)
T = int(input())
for test_case in range(1, T + 1):
a, b = map(int, input().split())
answer = 0
for i in range(a, b + 1):
temp = int(i ** 0.5)
if (temp ** 2) == i:
if str(i) == str(i)[::-1] and str(temp) == str(temp)[::-1]:
answer += 1
print(f"#{test_case} {answer}")
이진수 표현 (10726)
T = int(input())
for test_case in range(1, T + 1):
n, m = map(int, input().split())
binary = bin(m)[2:][::-1]
answer = "OFF"
if len(binary) < n:
pass
else:
if binary[:n] == '1' * n:
answer = "ON"
print(f"#{test_case} {answer}")
문자열의 거울상 (10804)
T = int(input())
for test_case in range(1, T + 1):
s = input()
mirror = {'b': 'd', 'd': 'b', 'p': 'q', 'q': 'p'}
answer = ''
for i in range(len(s) - 1, -1, -1):
answer += mirror[s[i]]
print(f"#{test_case} {answer}")
외로운 문자 (10912)
from collections import Counter
T = int(input())
for test_case in range(1, T + 1):
s = input()
counter = Counter(s).most_common()
answer = []
for i in range(len(counter)):
if int(counter[i][1]) % 2 != 0:
answer.append(counter[i][0])
if not answer:
print(f"#{test_case}", "Good")
else:
answer = ''.join(sorted(answer))
print(f"#{test_case} {answer}")
평범한 숫자 (11736)
T = int(input())
for test_case in range(1, T + 1):
n = int(input())
numbers = list(map(int, input().split()))
answer = 0
for i in range(1, n - 1):
if numbers[i - 1] < numbers[i] < numbers[i + 1] or numbers[i + 1] < numbers[i] < numbers[i - 1]:
answer += 1
print(f"#{test_case} {answer}")
반반 (11856)
from collections import Counter
T = int(input())
for test_case in range(1, T + 1):
s = input()
counter = Counter(s).most_common(2)
answer = ''
if len(counter) == 2:
if counter[0][1] == counter[1][1] == 2:
answer = "Yes"
else:
answer = "No"
else:
answer = "No"
print(f"#{test_case} {answer}")
구구단 1 (12004)
T = int(input())
for test_case in range(1, T + 1):
n = int(input())
numbers = []
answer = "Yes"
for i in range(9, 0, -1):
if n % i == 0:
numbers = [i, n // i]
break
for num in numbers:
if num > 9:
answer = "No"
print(f"#{test_case} {answer}")
구구단 (12221)
T = int(input())
for test_case in range(1, T + 1):
a, b = map(int, input().split())
answer = -1
if a // 10 >= 1 or b // 10 >= 1:
pass
else:
answer = a * b
print(f"#{test_case} {answer}")
24시간 (12368)
T = int(input())
for test_case in range(1, T + 1):
a, b = map(int, input().split())
time = a + b
if time >= 24:
time -= 24
print(f"#{test_case} {time}")
조별과제 (13218)
T = int(input())
for test_case in range(1, T + 1):
n = int(input())
print(f"#{test_case} {n // 3}")
일요일 (13229)
T = int(input())
day = {"SUN": 0, "MON": 1, "TUE": 2, "WED": 3, "THU": 4, "FRI": 5, "SAT": 6}
for test_case in range(1, T + 1):
s = input()
print(f"#{test_case} {7 - day[s]}")
댓글