Coding Test/HackerRank
[HackerRank] A Very Bing Sum c++
owls
2022. 7. 16. 20:32
728x90
- Problem
In this challenge, you are required to calculate and print the sum of the elements in an array, keeping in mind that some of those integers may be quite large.
- Function Description
Complete the aVeryBigSum function in the editor below. It must return the sum of all array elements.
aVeryBigSum has the following parameter(s):
- int ar[n]: an array of integers .
- sample input
5
1000000001 1000000002 1000000003 1000000004 1000000005
- output
5000000015
- solution (c++)
long aVeryBigSum(vector<long> ar) {
unsigned long int sum = 0;
for(auto &it : ar){
sum += it;
}
return sum;
}
- solution (python)
def aVeryBigSum(ar):
# Write your code here
ans = 0
for num in ar:
ans += int(num)
return ans
파이썬...자료형 신경안써도 되고 새삼 감탄
728x90