※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 26545번 문제인 Mathematics이다.
문제는 아래 링크를 확인하자.
https://www.acmicpc.net/problem/26545
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
주어지는 수의 개수 n을 먼저 읽고, 그 뒤에 주어지는 n개의 수를 합쳐 출력해 문제를 해결하자.
문제에 명시되어있지는 않지만, 주어지는 정수들을 부호 있는 64비트 정수를 이용해 입력받고 계산한 뒤 출력해도 충분히 문제를 통과할 수 있음을 확인했다. (아래의 제출 코드)
아래는 제출한 소스코드이다.
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;
ll N, ans;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> N;
while (N--) {
ll x; cin >> x;
ans += x;
}
cout << ans;
}
728x90
'BOJ' 카테고리의 다른 글
[BOJ 2321 // Fortran] Crowing (0) | 2022.12.19 |
---|---|
[BOJ 26495 // C++] Big Number (0) | 2022.12.19 |
[BOJ 26546 // C++] Reverse (0) | 2022.12.19 |
[BOJ 6887 // C++] Squares (0) | 2022.12.19 |
[BOJ 26592 // C++] Triangle Height (0) | 2022.12.19 |