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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • sqlserver 日期转字符串_sql server 字符串截取

    sqlserver 日期转字符串_sql server 字符串截取最近实习项目中需要用到sqlserver数据库,于是安装了之后使用了一下,觉得基本的sql语句是差不多的,区别就是给的函数不一样。在开发中遇到一个需求,需要将时间戳转化为datetime类型,具体如下:—-&gt;datetime我一开始百度之后发现是这样写:selectCONVERT(VARCHAR(20),DATEADD(SECOND,1533812469,…

    2022年10月8日
    2
  • 看了很多人的面试经验,我也来一段:这段时间的几个面试

    看了很多人的面试经验,我也来一段:这段时间的几个面试
    泉州巴黎婚纱摄影
     
    店门口摆了个牌子,说招聘20名数码师,月薪2000-4000。又在网上也看到招聘启事,投了。
     
    投完,人才网收到个面试通知,不过简历状态竟然是未阅?通知人面试连简历都不看的?打了个电话过去,又给了我个电话,再打过去,电话里跟我说,我们这个职位啊,工作时间长工资低(6+*12+,<=800),你要有心理准备……KAO,牌子上不是写的2000-4000吗?到底打的啥鬼主意?
     
    过阵子在百度PS吧,看到有人发了一个贴

    2022年5月4日
    77
  • awk与sed:关于多行的样本

    awk与sed:关于多行的样本

    2022年1月1日
    40
  • NOIP2012Day1T3-开车旅行

    NOIP2012Day1T3-开车旅行题解:首先我们可以分别建立小AAA和小BBB路程森林。其实森林也不用用边表去存储它,只要记录一下fa[i]fa[i]fa[i],即iii点的下一个点就可以了小AAA和小BBB旅行就等价于在这些森林里跑,很容易想到树上倍增。我们可以令f[i][j]f[i][j]f[i][j]为当前AAA开车在第iii个点经过2j2j2^j天后到达的点g1[i][j]g1[i][j]g1[i][j…

    2022年8月22日
    8
  • 【优化算法】简述灰狼优化算法(GWO)原理[通俗易懂]

    【优化算法】简述灰狼优化算法(GWO)原理[通俗易懂]系列优化算法简述:OP_1.简述遗传算法(GA)原理OP_2简述灰狼优化算法(GWO)原理前言:灰狼优化算法(GreyWolfOptimizer,GWO)由澳大利亚格里菲斯大学学者Mirjalili等人于2014年提出来的一种群智能优化算法。该算法受到了灰狼捕食猎物活动的启发而开发的一种优化搜索方法,它具有较强的收敛性能、参数少、易实现等特点。近年来受到了学者的广泛关注…

    2022年10月19日
    2
  • vs2008sp1补丁怎么安装_win10系统怎么安装cad2005

    vs2008sp1补丁怎么安装_win10系统怎么安装cad2005我第一次安装这个补丁的时候就挂了,搞得VS2005和相关的一些程序都不能运行,后来在网上找到了一些解决方法,结合自己的实际体验,写了这篇教程。补丁相关资料:简体中文版补丁名称:VS80sp1-KB926604-X86-CHS.exe版本:50727.762知识库(KB)文章:KB928957发布日期:2006/12/14简体中文版补丁大小:430

    2022年9月28日
    2

发表回复

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

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