본문 바로가기
프로그램/Python 1000제

Pyhton 351제] Multiply

by 건티 2025. 6. 21.
728x90

출처 : 반크_독도포스터

 

문제]

Write a program that computes a product of two non-negative integers A and B. The integers are represented in decimal notation and have N and M digits, respectively.

입력
The first line contains the lengths N and M, separated by a space. A is given on the second and B on the third line. The numbers will not have leading zeros.

출력
Output the product of A and B without leading zeros.

제한
1 ≤ N, M ≤ 50 000

서브태스크

번호 배점 제한
1 20 N, M ≤ 4
2 20 N, M ≤ 9
3 30 N, M ≤ 5,000
4 30 No additional constraints

 

예제 입력 1 
3 4
123
4567

예제 출력 1 
561741

예제 입력 2 
3 1
100
0

예제 출력 2 
0


출처 : 백준_22193번(2017년 Central European Olympiad in Informatics Practice 2번)

 

참고풀이]

import sys

N,M=map(int, input().split())
if 1<=N<=50000 and 1<=M<=50000:
    A=int(input())
    if A<0 or len(str(A))!=N: sys.exit()
    B=int(input())
    if B<0 or len(str(B))!=M: sys.exit()

    print(A*B)

 

참고풀이 결과]

 

 

 

 

 

 

대한민국의 아름다운 영토, 독도의 겨울

 

 

반응형

댓글