A. Initial Bet(Codeforces Round #273)

A. Initial Bet(Codeforces Round #273)

大家好,又见面了,我是全栈君,今天给大家准备了Idea注册码。

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 of b, 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:

  1. One coin is passed from the fourth player to the second player;
  2. One coin is passed from the fourth player to the fifth player;
  3. One coin is passed from the first player to the third player;
  1. One coin is passed from the fourth player to the second player.      

判一下是否为5的倍数,注意特判全为0

代码:

#include <iostream>
#include <cstdio>
using namespace std;

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

版权声明:本文博客原创文章。博客,未经同意,不得转载。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/117712.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

  • C#遍历Dictionary

    C#遍历Dictionary方法推荐:http://www.cnblogs.com/roucheng/p/3521864.html

    2021年12月25日
  • Etcd – 分布式配置中心

    Etcd – 分布式配置中心Etcd简介Etcd是一种分布式kv存储设施,他具有一定的一致性,高性能,高可用的方案.类似的zookeeper,但没有zookeeper那么重型,功能也没有覆盖那么多.简单直接的应用就是配置中心架构设计总览clients为多个需要配置的服务,中间层为多个grpc-proxy做均衡负载,以免一个proxy挂了之后导致单点问题.grpc…

    2022年10月30日
  • MethodFilterInterceptor和AbstractInterceptor的比较

    MethodFilterInterceptor和AbstractInterceptor的比较在编写自定义拦截器的时候,需要继承AbstractInterceptor或者MethodFilterInterceptor,那么他们有什么不同呢首先查看MethodFilterInterceptor的源代码我们发现MethodFilterInterceptor也是继承了AbstractInterceptor的,并且MethodFilterInterceptor里面定义了两个参数,分别是excl…

  • Android 代码混淆 选项说明[通俗易懂]

    Android 代码混淆 选项说明[通俗易懂]转载请注明出处:Android代码混淆选项说明http://blog.csdn.net/jjwwmlp456/article/details/44977721—————–匆忙拥挤repeat语法规范说明地址:https://stuff.mit.edu/afs/sipb/project/android/sdk/android-…

  • matlab secant method

    matlab secant method

    2021年12月16日
  • ie浏览器最大化快捷键(电脑退出最大化快捷键)

    最小化的快捷键 WIN+M 按“Windows键+M”键可以最小化所有被打开的窗口,相当于“显示桌面”功能。·窗口最大化快捷键 Shift+WIND+MWindows键+CTRL+M功能是:重新将恢复上一项操作前窗口的大小和位置·在最大化和最小化之间切换的快捷键:WIN+D· 最大化ALT+空格+X  最小化ALT+空格+N其它有关WINDOWS键的快捷

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号