Alternative Adder

View as PDF

Submit solution


Points: 10 (partial)
Time limit: 1.0s
Memory limit: 32M

Author:
Problem type
Allowed languages
Python

Problem Statement

Please write a function called "adder" that can accept an arbitrary number of arguments.

The adder function should add the first argument, then subtract the second argument, add the third argument, and so on.

Please only submit the adder function that you define.

You may test your adder function locally by inserting the following snippet in your code:

if __name__ == '__main__':
    t = int(input())
    for i in range(1, t+1):
        args = map(int, input().split())
        print("Case #%d: %d" % (i, adder(*args)))

Input Specification

The first line of the input gives the number of test cases, T, T test cases follow. Each test case consists of a line. The line contains N arguments of adder function, seperated by a space.

Limits

Memory limits: 32MB.

Time limits: 1 second.

1 \leq T \leq 100

1 \leq N \leq 10000

Test Set 1

Sample Case

Test Set 2

1 \leq N \leq 100

Test Set 3

1 \leq N \leq 1000

Test Set 4

1 \leq N \leq 10000

Output Specification

For each test case, output one line containing Case #x: y, where x is the case number(starting from 1), and y is the result after calling your adder function.

Sample Input

3
3 0 1
1
-7 4 8 -5

Sample Output

Case #1: 4
Case #2: 1
Case #3: 2

Explaination

In Case#1 we will call adder(3,0,1) in our main function, the result will be 4 since 3 - 0 + 1 = 4

In Case#2 we will call adder(1) in our main function, the result will be 1.

In Case#3 we will call adder(-7,4,8,-5) in our main function, the result will be 2 since -7 - 4 + 8 -(-5) = 2

Hint

Variable Length Arguments


Comments

There are no comments at the moment.