본문 바로가기
Study (etc)/Problem Solving

[BOJ / C++] 26545번 : Mathematics

by Haren 2022. 12. 20.

문제

A mathematician has stolen your calculator! Luckily, you know how to code and can write a program that adds together numbers. Write a program that adds together a list of integers.

입력

The first line will contain a single integer n that indicates the number of integers to add together. The next n lines will each contain one integer. Your task is to write a program that adds all of the integers together.

출력

Output the resulting integer. The output should be one line containing one integer value.

Solved.ac 레벨

브론즈 V

풀이

#include <bits/stdc++.h>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n, sum = 0;
    cin >> n;

    while(n--){
        int input;
        cin >> input;
        sum += input;
    }

    cout << sum << "\n";

    
    return 0;
}

 

 

26545번: Mathematics

A mathematician has stolen your calculator! Luckily, you know how to code and can write a program that adds together numbers. Write a program that adds together a list of integers.

www.acmicpc.net

 

'Study (etc) > Problem Solving' 카테고리의 다른 글

[BOJ / C++] 5426번 : 비밀편지  (0) 2022.12.26
[BOJ / C++] 26307번 : Correct  (0) 2022.12.21
[BOJ / C++] 26574번 : Copier  (0) 2022.12.20
[BOJ / C++] 5341번 : Pyramids  (0) 2022.12.17
[BOJ / C++] 20254번 : Site Score  (0) 2022.12.15