# swea 1216 '회문2'

T = 10
for t in range(1, T+1):
    t = int(input())
    MAP = []
    for _ in range(100):
        MAP.append(list(input()))

    max_length = 0
    for length in range(100, 0, -1):
        for i in range(100 - length + 1):
            for j in range(100 - length + 1):
                j_offset = 0
                j_flag = True
                while j_offset < length // 2:
                    if MAP[i][j + j_offset] != MAP[i][j + length - 1 - j_offset]:
                        j_flag = False
                        break
                    j_offset += 1

                if j_flag:
                    max_length = length
                    break

                i_offset = 0
                i_flag = True
                while i_offset < length // 2:
                    if MAP[i + i_offset][j] != MAP[i + length - 1 - i_offset][j]:
                        i_flag = False
                        break
                    i_offset += 1

                if i_flag:
                    max_length = length
                    break
            if max_length:
                break
        if max_length:
            break

    print('#{} {}'.format(t, max_length))
# swea 3143 '가장 빠른 문자열 타이핑'

T = int(input())

for t in range(1, T+1):
    A, B = input().strip().split()

    jump_dict = {}
    for i in range(1, len(B)):
        if B[-1 - i] in jump_dict:
            continue
        jump_dict[B[-1 - i]] = i

    cnt = 0
    i = len(B) - 1
    k = 0

    while i < len(A):
        if k == len(B):
            jump = len(B)
            cnt += 1
            i += jump
            k = 0
            continue

        if A[i - k] == B[-1 - k]:
            k += 1
        else:
            jump = jump_dict.get(A[i], len(B))
            i += jump
            k = 0

    result = len(A) - cnt * (len(B) - 1)

    print('#{} {}'.format(t, result))
#swea 12595 '마법사의 사냥'

di = [1, 1, -1, -1]
dj = [1, -1, 1, -1]

T = 5
for t in range(1, T+1):
    N = int(input())
    MAP = [[-1 for j in range(N + 2)] for i in range(N + 2)]

    for i in range(1, N + 1):
        lst = list(map(int, input().split()))
        for j in range(1, N + 1):
            MAP[i][j] = lst[j - 1]
    
    K = int(input())
    
    max_total = 0
    for i in range(1, N + 1):
        for j in range(1, N + 1):
            total = 0
            for d in range(4):
                for k in range(1, K + 1):
                    test_i = i + di[d] * k
                    test_j = j + dj[d] * k
                    if MAP[test_i][test_j] == -1:
                        break
                    total += MAP[test_i][test_j]
            if max_total < total:
                max_total = total
    
    print('#{} {}'.format(t, max_total))
# 프로그래머스 '다리를 지나는 트럭'
# https://programmers.co.kr/learn/courses/30/lessons/42583

from collections import deque

def solution(bridge_length, weight, truck_weights):
    time = 0

    i = 0
    w = 0
    que = deque([0 for _ in range(bridge_length)])

    while True:
        if i == len(truck_weights):
            time += bridge_length
            break
        
        w -= que.popleft()

        if w + truck_weights[i] <= weight:
            w += truck_weights[i]
            que.append(truck_weights[i])
            i += 1
        
        else:
            que.append(0)
        
        time += 1

    return time


if __name__=='__main__':
    test_cases = [
        {
            'bridge_length': 2,
            'weight': 10,
            'truck_weights': [7,4,5,6],
            'answer': 8
        }
    ]

    for test_case in test_cases:
        bridge_length = test_case['bridge_length']
        weight = test_case['weight']
        truck_weights = test_case['truck_weights']
        answer = test_case['answer']
        my_answer = solution(bridge_length, weight, truck_weights)

        print('answer: {}, my_answer: {}'.format(answer, my_answer))
# 프로그래머스 '주식 가격'
# https://programmers.co.kr/learn/courses/30/lessons/42584

class Stock:
    def __init__(self, price, time):
        self.price = price
        self.time = time

def solution(prices):

    answer = [0 for _ in range(len(prices))]

    stack = []

    time = 0

    while time < len(prices):
        if len(stack) == 0:
            stack.append(Stock(prices[time], time))
            time += 1
            continue

        price = prices[time]
        top = stack[-1]

        if top.price > price:
            answer[top.time] = time - top.time
            stack.pop()
            continue
        
        stack.append(Stock(price, time))
        time += 1

    time -= 1

    while len(stack):
        pop = stack.pop()
        answer[pop.time] = time - pop.time

    return answer


if __name__=='__main__':
    prices = [1, 2, 3, 2, 3]
    answer = [4, 3, 1, 1, 0]
    my_answer = solution(prices)

    print('answer: {}, my_answer: {}'.format(answer, my_answer))
# 프로그래머스 '프린터'
# https://programmers.co.kr/learn/courses/30/lessons/42587

from collections import deque

class Print:
    def __init__(self, idx, priority):
        self.idx = idx
        self.priority = priority


def solution(priorities, location):
    print_que = deque([])
    priority_que = deque([])
    cnt_list = [0 for _ in range(10)]

    for idx, priority in enumerate(priorities):
        print_que.append(Print(idx, priority))
        cnt_list[priority] += 1
    
    for priority in range(9, 0, -1):
        while cnt_list[priority]:
            priority_que.append(priority)
            cnt_list[priority] -= 1
    
    answer = 0
    while True:
        print: Print = print_que.popleft()
        if print.priority == priority_que[0]:
            answer += 1
            priority_que.popleft()
            if print.idx == location:
                break
        else:
            print_que.append(print)

    return answer
# 프로그래머스 '기능개발'
# https://programmers.co.kr/learn/courses/30/lessons/42586

from collections import deque
import math

def solution(progresses, speeds):

    p_que = deque(progresses)
    s_que = deque(speeds)

    
    time = 0
    answer = []

    while len(p_que):
        time = math.ceil((100 - p_que[0]) / s_que[0])
        
        cnt = 0
        while len(p_que)  and  100 - p_que[0] <= s_que[0] * time:
            p_que.popleft()
            s_que.popleft()
            cnt += 1
        
        answer.append(cnt)
    return answer


if __name__=='__main__':
    
    test_cases = [
        {
            'progresses': [93, 30, 55],
            'speeds': [1, 30, 5],
            'answer': [2, 1] 
        },
        {
            'progresses': [95, 90, 99, 99, 80, 99],
            'speeds': [1, 1, 1, 1, 1, 1],
            'answer': [1, 3, 2]
        }
    ]
    
    for test_case in test_cases:
        progresses = test_case['progresses']
        speeds = test_case['speeds']
        answer = test_case['answer']
        my_answer = solution(progresses, speeds)

        print(f'answer: {answer}, my_answer: {my_answer}')
# 프로그래머스 문제 '전화번호 목록'
# https://programmers.co.kr/learn/courses/30/lessons/42577

def solution(phone_book: list):
    book_dict = {}

    for phone_num in phone_book:
        book_dict[phone_num] = 1
    
    for phone_num in phone_book:
        for i in range(1, len(phone_num)):
            compare_num = phone_num[:i]
            if book_dict.get(compare_num):
                return False
    
    return True


if __name__=='__main__':

    test_cases = [
        {
            'phone_book': ["119", "97674223", "1195524421"],
            'answer': False 
        },
        {
            'phone_book': ["123","456","789"],
            'answer': True
        },
        {
            'phone_book': ["12","123","1235","567","88"],
            'answer': False
        }
    ]
    
    for test_case in test_cases:
        phone_book = test_case['phone_book']
        answer = test_case['answer']
        my_answer = solution(phone_book)

        print(f'answer: {answer}, my_answer: {my_answer}')

+ Recent posts