IT/Programming / / 2022. 7. 8. 17:06

[백준, Python] 2675번 문자열 반복

반응형
1 초 128 MB 130549 66082 56678 50.807%

문제

문자열 S를 입력받은 후에, 각 문자를 R번 반복해 새 문자열 P를 만든 후 출력하는 프로그램을 작성하시오. 즉, 첫 번째 문자를 R번 반복하고, 두 번째 문자를 R번 반복하는 식으로 P를 만들면 된다. S에는 QR Code "alphanumeric" 문자만 들어있다.

QR Code "alphanumeric" 문자는 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ\$%*+-./: 이다.

입력

첫째 줄에 테스트 케이스의 개수 T(1 ≤ T ≤ 1,000)가 주어진다. 각 테스트 케이스는 반복 횟수 R(1 ≤ R ≤ 8), 문자열 S가 공백으로 구분되어 주어진다. S의 길이는 적어도 1이며, 20글자를 넘지 않는다. 

출력

각 테스트 케이스에 대해 P를 출력한다.

 


더보기

 

# 1차 입력값 처리
def chkInput(caseCntInput, testCaseList=None):
    # 케이스 개수 체크 (1 ~ 1000)
    if not (1 <= caseCntInput <= 1000):
        raise Exception('케이스 갯수가 잘못됐습니다.')

    # 케이스 반복 횟수 체크
    for testCase in testCaseList:
        caseLength = len(testCase)

        # 입력값이 두개가 아닐 때
        if caseLength != 2:
            raise Exception('입력값이 2개가 아닙니다.')

        # 케이스 반복 횟수 (0 ~ 8)
        if not (1 <= int(testCase[0]) <= 8):
            raise Exception('케이스 반복횟수가 잘못됐습니다.')


# 결과값 계산
def calOutput(testCaseList=None):
    funcResult = []

    for testCase in testCaseList:
        resultList = []
        resultSplit = list(testCase[1])

        for index in range(0, len(resultSplit)):
            caseRepCnt = int(testCase[0])
            while caseRepCnt > 0:
                caseRepCnt -= 1
                resultList.append(resultSplit[index])

        funcResult.append(resultList)

    return funcResult


try:
    caseCntInput = int(input())
    caseList = []
    resultList = []
    for index in range(0, caseCntInput):
        caseList.append(list(input().split()))

    chkInput(caseCntInput, caseList)
    resultList = calOutput(caseList)

    for result in resultList:
        print("".join(result))

except Exception as e:
    print(e)​

 

반응형
  • 네이버 블로그 공유
  • 네이버 밴드 공유
  • 페이스북 공유
  • 카카오스토리 공유