갓비니

2020/04/11 코딩 문제 연습 (7단계 / 백준 15596번, 함수 - C++ 구현이 어려움) 본문

Programming/코딩 문제 풀이

2020/04/11 코딩 문제 연습 (7단계 / 백준 15596번, 함수 - C++ 구현이 어려움)

갓비니 2020. 4. 11. 00:23

<15596번>

 

1
2
3
4
5
6
7
8
long long sum(int *a, int n) {
    long long num = 0;
    for (int i = 0; i < n; i++)
    {
        num += a[i];
    }
    return num;
}
 

c로 푼 내용.

제출 메뉴를 누르니 이미 함수의 틀이 완성되어있었다.

 

<어려운 구현 C++>

1
2
3
4
5
6
7
8
#include <vector>
using namespace std;
long long sum(vector<int> &a) {
    long long ans = 0;
    for(vector<int>::iterator i = a.begin(); i < a.end(); i++)
        ans += *i;
    return ans;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter