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;
}

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

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

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

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • PyTorch建立resnet34和resnet101代码[通俗易懂]

    PyTorch建立resnet34和resnet101代码[通俗易懂]model.pyimporttorch.nnasnnimporttorchclassBasicBlock(nn.Module):expansion=1def__init__(self,in_channel,out_channel,stride=1,downsample=None):super(BasicBlock,self).__init__()self.conv1=nn.Conv2d(in_channels=

    2022年9月28日
    3
  • Java之Java开发工具

    Java之Java开发工具

    2021年7月21日
    61
  • alibaba map转json_fastjson字符串转对象

    alibaba map转json_fastjson字符串转对象JSONObjectobj=newJSONObject();{obj.put(“key1″,”value1”);obj.put(“key2″,”value2”);obj.put(“key3″,”value3”);}Map<String,String>params=JSONObject.parseObject(obj.toJSONString(),ne…

    2022年8月23日
    11
  • 树的先序遍历对应二叉树的_先序遍历输入一个二叉树

    树的先序遍历对应二叉树的_先序遍历输入一个二叉树笔试特别喜欢考这种题。先说一下思路。首先,需要明白前序、中序、后序遍历:①前序:根→左→右②中序:左→根→右③后序:左→右→根仅明白这个是不行的,还需要技巧。对于标题中的问题,我们很容易判断根节点是A,A的右节点是B,A的左边有CDFEGH,如下图:然后,将问题进行分解。去掉了AB结点之后,问题可分解如下:按照同样的套路,我们可以画出子问题的数大大概结构,如下图:与第一步画…

    2025年8月28日
    5
  • Python中安装requests库总是报错的解决方法

    今晚学爬虫,要安装requests库。文章上说,直接在终端窗口执行如下命令就行。pipinstallrequests然而我还是失败了。在电脑前坐了一个小时,找过很多解决方法的博客,都无济于事。终于看到了有位大佬写的博客,试了下代码。一下就成功了!现分享如下:pipinstallrequests-ihttp://pypi.douban.com/simple–trust…

    2022年4月9日
    377
  • 图像处理之双线性插值法「建议收藏」

    图像处理之双线性插值法「建议收藏」1、线性插值的解释单线性插值法双线性插值法2、另一位牛人讲的比较易懂1.双线性插值2.存在的问题3、又是另一位讲的通俗易懂1,原理2,计算方法3,加速以及优化策略3.1源图像和目标图像几何中心的对齐  3.2将浮点运算转换成整数运算4,代码…

    2022年6月4日
    32

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

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