Backyardigans and game of Bounty
The Backyardigans are the five spirited friends Uniqua, Pablo, Tyrone, Tasha, & Austin.
Their vivid imaginations take them on epic musical journeys in their own backyard by playing, dancing and singing.
This time they set out to play a game called “Bounty”.
Each friend gives a non-zero number of candies b as an initial bet. After all friends make their bets of b candies, the following operation is repeated for several times: a candy is passed from one friend to some other friend.
Given the number of candies each friend has at the end of the game, your task is to write a program that can determine the size b of the initial bet or find out that such outcome of the game cannot be obtained for any positive number of candies b in the initial bet.
Input Format:
The input consists of a single line containing five integers c 1, c 2, c 3, c 4 and c 5, which corresponds to the number of candies that the first, second, third, fourth and fifth friends respectively have at the end of the game (0 ≤ c 1, c 2, c 3, c 4, c 5 ≤ 100).
Output Format:
Print the only line containing a single positive integer b — the number of candies in the initial bet of each friend. If there is no such value of b, then print the only value "-1" (quotes for clarity).
Sample Input1:
2 5 4 0 4
Sample Output1:
3
Sample Input2:
4 5 9 2 1
Sample Output2:
-1
Solution
Given program
01 | { |
02 | #include |
03 | int ans=0, i; |
04 | { |
05 | printf("-1\n"); |
06 | {scanf("%d",&a[i]); |
07 | } |
08 | } |
09 | for(i=0;i<5 code="" i="">5> |
10 | return 0; |
11 | printf("%d\n",ans/5); |
12 | int main() |
13 | if(ans%5==0) |
14 | else |
15 | ans+=a[i]; |
16 | printf ("-1\n"); |
17 | } |
18 | return 0; |
19 | int a [10]; |
20 | if (ans==0) |
Actual
#include |
02 | int main() |
03 | { |
04 | int ans=0, i; |
05 | int a [10]; |
06 | for(i=0;i<5 code="" i="">5> |
07 | { |
08 | {scanf("%d",&a[i]); |
09 | if (ans==0) |
10 | ans+=a[i]; |
11 | printf("%d\n",ans/5); |
12 | } |
13 | if(ans%5==0) |
14 | printf("-1\n"); |
15 | else |
16 | printf ("-1\n"); |
17 | return 0; |
18 | } |
19 | return 0; |
20 | } |
-1
3
1 2 1 2 3
-1
0 -1
0
-1
4
57 83 11 4 93
-1
11 -1
11
-1
5
2 3 4 5 6
4
0 -1
4
0
-1
6
100 100 100 100 100
100
20 -1
10
2
0
-1
7
2 5 4 0 4
3
0 -1
3
0
-1
8
93 100 99 90 98
96
18 -1
96
18
-1
9
43 83 1 0 23
30
8 -1
30
8
-1
10
4 5 9 2 1
-1
0 -1
0
-1

No comments: