반응형
Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Archives
Today
Total
05-18 06:40
관리 메뉴

ImJay

[파이썬/Python] 백준 7891번 Can you add this? 본문

Solved.ac - Python/Bronze V

[파이썬/Python] 백준 7891번 Can you add this?

ImJay 2023. 6. 5. 04:46
반응형

[파이썬/Python] 백준 7891번 Can you add this?

 

7891번: Can you add this?

The input contains several test cases. The first line contains and integer t (t ≤ 100) denoting the number of test cases. Then t tests follow, each of them consisiting of two space separated integers x and y (−109 ≤ x, y ≤ 109).

www.acmicpc.net


문제

Given two integers, calculate and output their sum.

두 정수가 주어졌을 때, 그들의 합을 계산하고 출력해야 합니다.

입력

The input contains several test cases. The first line contains and integer t (t ≤ 100) denoting the number of test cases. Then t tests follow, each of them consisiting of two space separated integers x and y (−109 ≤ x, y ≤ 109).

입력은 여러 개의 테스트 케이스로 구성됩니다. 첫 번째 줄에는 테스트 케이스의 개수를 나타내는 정수 t (t ≤ 100)가 주어집니다. 그런 다음 t개의 테스트가 이어지며, 각 테스트는 두 개의 공백으로 구분된 정수 x와 y (−10^9 ≤ x, y ≤ 10^9)로 이루어집니다.

출력

For each test case output output the sum of the corresponding integers.

각 테스트 케이스에 대해, 해당하는 정수들의 합을 출력합니다.

예제 입력

4
-100 100
2 3
0 110101
-1000000000 1

예제 출력

0
5
110101
-999999999

풀이

# 테스트 케이스의 개수를 입력
t = int(input())

# t번의 테스트를 수행
for _ in range(t):
    # 정수 x와 y를 공백을 기준으로 분리하여 입력
    a, b = map(int, input().split())

    # 정수 x와 y의 합을 계산하여 출력
    print(a + b)

이 프로그램은 입력값으로 테스트 케이스의 개수 t와 t개의 테스트 케이스를 받아서 각 테스트 케이스의 정수들의 합을 계산하고 출력한다. t번의 반복문을 수행하며, 각 반복에서 곱셈 연산 하나가 수행되므로 상수 시간에 이루어진다. 따라서 시간 복잡도는 O(t)이다. 입력 크기에 비례하여 실행 시간이 증가한다.

반응형
Comments