본문 바로가기

Algorithm/Implementation

(C++) - 백준(BOJ) 7891 : Can you add this?

반응형

https://www.acmicpc.net/problem/7891

 

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

 

간단한 구현 문제였습니다.

📕 풀이방법

📔 입력 및 초기화

 1. test case t를 선언 후 입력받습니다. 2. while loop를 t만큼 수행하며 지역변수 a, b를 선언해 입력받습니다.

 

📔 풀이과정

범위가 -10억 ~ 10억이므로 두 수를 더했을 때 int범위를 초과하지 않습니다.

📔 정답출력

a + b를 출력해줍니다.


📕 Code

#include <bits/stdc++.h>
using namespace std;
int t;
int main(){
    cin >> t;
    while(t--){
        int a, b;
        cin >> a >> b;
        cout << a + b << '\n';
    }
}