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


相关推荐

  • UML概述及UML图详解[通俗易懂]

    UML概述及UML图详解[通俗易懂]​UML概述一、UML简介(一)UML(UnifiedModelingLanguage)为面向对象软件设计提供统一的、标准的、可视化的建模语言。适用于描述以用例为驱动,以体系结构为中心的软件设计的全过程。(二)UML的定义包括UML语义和UML表示法两个部分。 1.UML语义:UML对语义的描述使开发者能在语义上取得一致认识,消除了因人而异的表达方法所造成的影响; 2.UML表…

    2025年8月21日
    3
  • jasypt加密原理_encrypt加密

    jasypt加密原理_encrypt加密没什么好说的了,直接看demo。添加依赖 &amp;amp;amp;amp;lt;dependency&amp;amp;amp;amp;gt; &amp;amp;amp;amp;lt;groupId&amp;amp;amp;amp;gt;com.github.ulisesbocchio&amp;amp;amp;amp;lt;/groupId&amp;amp;amp;amp;gt; &amp;amp;amp;amp;lt

    2022年9月26日
    3
  • Hash算法的讲解[通俗易懂]

    Hash算法的讲解[通俗易懂]散列表,又叫哈希表,它是基于快速存取的角度设计的,也是一种典型的“空间换时间”的做法。顾名思义,该数据结构可以理解为一个线性表,但是其中的元素不是紧密排列的,而是可能存在空隙。散列表(Hashta

    2022年8月5日
    7
  • Pytest(6)重复运行用例pytest-repeat[通俗易懂]

    Pytest(6)重复运行用例pytest-repeat[通俗易懂]前言平常在做功能测试的时候,经常会遇到某个模块不稳定,偶然会出现一些bug,对于这种问题我们会针对此用例反复执行多次,最终复现出问题来。自动化运行用例时候,也会出现偶然的bug,可以针对单个用例,

    2022年7月30日
    4
  • 多元线性回归推导过程

    多元线性回归推导过程接上篇 人工智能开篇常用算法一多元线性回归详解 1 此次我们来学习人工智能的第一个算法 多元线性回归 文章会包含必要的数学知识回顾 大部分比较简单 数学功底好的朋友只需要浏览标题 简单了解需要哪些数学知识即可 本章主要包括以下内容数学基础知识回顾什么是多元线性回归多元线性回归的推导过程详解如何

    2025年8月1日
    4
  • UE4 显示帧率的几种姿势「建议收藏」

    在使用UE4Editor或者UE4Game时,有时候需要查看帧率,以及每帧耗时情况。在Editor中显示:键盘上按下~可以看到有个输入框出现:在输入框输入statfps或者statunit,出现帧率或者耗时:在Game中显示(1):启动Game.exe后,键盘按下~出现输入框,输入框中输入statfps或者statunit,回车:在

    2022年4月14日
    324

发表回复

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

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