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
03int ans=0, i;
04{
05printf("-1\n");
06{scanf("%d",&a[i]);
07}
08}
09for(i=0;i<5 code="" i="">
10return 0;
11printf("%d\n",ans/5);
12int main()
13if(ans%5==0)
14else
15ans+=a[i];
16printf ("-1\n");
17}
18return 0;
19int a [10];
20if (ans==0)
Actual
#include
02int main()
03{
04int ans=0, i;
05int a [10];
06for(i=0;i<5 code="" i="">
07{
08{scanf("%d",&a[i]);
09if (ans==0)
10ans+=a[i];
11printf("%d\n",ans/5);
12}
13if(ans%5==0)
14printf("-1\n");
15else
16printf ("-1\n");
17return 0;
18}
19return 0;
20}



01#include
02
03int main()
04{
05    int a [10];
06    int ans=0, i;
07    for(i=0;i<5 code="" i="">
08    {scanf("%d",&a[i]);
09    ans+=a[i];
10    }
11    if (ans==0)
12    {
13        printf ("-1\n");
14        return 0;
15    }
16    if(ans%5==0)
17    printf("%d\n",ans/5);
18    else
19    printf("-1\n");
20    return 0;
21}



S.NOInputExpected OutputObtained OutputDifferences
199 98 98 99 100-119 -119-1
2100 0 0 0 02020 -120

-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: