【CODEFORCES】 A. Initial Bet

A. Initial Bet
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
There are five people playing a game called "Generosity". Each person gives some non-zero number of coins b as an initial bet. After all players make their bets of b coins, the following operation is repeated for several times: a coin is passed from one player to some other player.
Your task is to write a program that can, given the number of coins each player has at the end of the game, 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 coins b in the initial bet.
Input
The input consists of a single line containing five integers c1, c2, c3, c4 and c5 — the number of coins that the first, second, third, fourth and fifth players respectively have at the end of the game (0 ≤ c1, c2, c3, c4, c5 ≤ 100).
Output
Print the only line containing a single positive integer b — the number of coins in the initial bet of each player. If there is no such value ofb, then print the only value "-1"(quotes for clarity).
Sample test(s)
input
2 5 4 0 4

output
3

input
4 5 9 2 1

output
-1

Note
In the first sample the following sequence of operations is possible:
One coin is passed from the fourth player to the second player;
One coin is passed from the fourth player to the fifth player;
One coin is passed from the first player to the third player;
One coin is passed from the fourth player to the second player.
문제풀이: 5를 다 나눌 수 있는지 없는지를 합치면 된다.
sum==0을 주의할 때도 -1을 출력해야 한다.
#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

int a,sum;

int main()
{
    for (int i=1;i<=5;i++)
    {
        scanf("%d",&a);
        sum+=a;
    }
    if (sum==0) printf("-1
"); else if (sum%5==0) printf("%d
",sum/5); else printf("-1
"); return 0; }

좋은 웹페이지 즐겨찾기