ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • A Very Big Sum
    개발 모음집/HackerRank 2021. 1. 17. 20:50

    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 .

    Return

    • long: the sum of all array elements

    Input Format

    The first line of the input consists of an integer .
    The next line contains  space-separated integers contained in the array.

    Output Format

    Return the integer sum of the elements in the array.

    Constraints

    Sample Input

    5 1000000001 1000000002 1000000003 1000000004 1000000005

    Output

    5000000015

     

    #!/bin/python3
    
    import math
    import os
    import random
    import re
    import sys
    
    # Complete the aVeryBigSum function below.
    def aVeryBigSum(ar):
        sum = 0
        for sum_data in ar:
            sum += sum_data
        return sum
    
    if __name__ == '__main__':
        fptr = open(os.environ['OUTPUT_PATH'], 'w')
    
        ar_count = int(input())
    
        ar = list(map(int, input().rstrip().split()))
    
        result = aVeryBigSum(ar)
    
        fptr.write(str(result) + '\n')
    
        fptr.close()
    

    '개발 모음집 > HackerRank' 카테고리의 다른 글

    Birthday Cake Candles  (0) 2021.01.17
    Mini-Max Sum  (0) 2021.01.17
    Staircase  (0) 2021.01.17
    Plus Minus  (0) 2021.01.17
    Diagonal Difference  (0) 2021.01.17
    Compare the Triplets  (0) 2021.01.17
    Simple Array Sum  (0) 2021.01.17
    Solve Me First  (0) 2021.01.17
Designed by Tistory.