문제 링크입니다: https://www.acmicpc.net/problem/15596
15596번: 정수 N개의 합
정수 n개가 주어졌을 때, n개의 합을 구하는 함수를 작성하시오. 작성해야 하는 함수는 다음과 같다. C, C11, C (Clang), C11 (Clang): long long sum(int *a, int n); a: 합을 구해야 하는 정수 n개가 저장되어 있는 배열 (0 ≤ a[i] ≤ 1,000,000, 1 ≤ n ≤ 3,000,000) n: 합을 구해야 하는 정수의 개수 리턴값: a에 포함되어 있는 정수 n개의 합 C++, C++11, C++14,
www.acmicpc.net
간단한 함수 작성 문제였습니다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <vector> | |
long long sum(std::vector<int> &a) { | |
long long result = 0; | |
for (int i = 0; i < a.size(); i++) { | |
result += a[i]; | |
} | |
return result; | |
} |

개발환경:Visual Studio 2017
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > BOJ' 카테고리의 다른 글
백준 17299번 오등큰수 (0) | 2020.01.31 |
---|---|
백준 1526번 가장 큰 금민수 (1) | 2020.01.30 |
백준 1816번 암호 키 (8) | 2019.11.25 |
백준 3671번 산업 스파이의 편지 (0) | 2019.11.24 |
백준 2355번 시그마 (0) | 2019.11.11 |