2069:【例2.12 】糖果游戏(2069: [example 2.12] candy game)

【题目描述】

某幼儿园里,有5个小朋友编号为1、2、3、4、5,他们按自己的编号顺序围坐在一张圆桌旁。他们身上都有若干个糖果(键盘输入),现在他们做一个分糖果游戏。从1号小朋友开始,将自己的糖果均分三份(如果有多余的糖果,则立即吃掉),自己留一份,其余两份分给他的相邻的两个小朋友。接着2号、3号、4号、5号小朋友同样这么做。问一轮后,每个小朋友手上分别有多少糖果。

【输入】

5个小朋友的糖果数。

【输出】

游戏后5个小朋友的糖果数。(按5位宽度输出)

【输入样例】

8 9 10 11 12

【输出样例】

   11    7    9   11    6
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d,e;
    cin>>a>>b>>c>>d>>e;
    a=a/3;b=b+a;e=e+a;
    b=b/3;c=c+b;a=a+b;
    c=c/3;d=d+c;b=b+c;
    d=d/3;e=e+d;c=c+d;
    e=e/3;a=a+e;d=d+e;
    cout<<setw(5)<<a<<setw(5)<<b<<setw(5)<<c<<setw(5)<<d<<setw(5)<<e; 
}
————————

[Title Description]

In a kindergarten, there are five children numbered 1, 2, 3, 4 and 5. They sit around a round table according to their numbering order. They all have several sweets (keyboard input), and now they play a candy game. Starting from child No. 1, divide his candy into three equal portions (if there is any extra candy, eat it immediately), keep one and give the other two to his two adjacent children. Then children 2, 3, 4 and 5 do the same. Ask how many sweets each child has in hand after a round.

[input]

The number of sweets for five children.

[output]

The number of candies for five children after the game. (output by 5-bit width)

[input example]

8 9 10 11 12

[output example]

   11    7    9   11    6
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d,e;
    cin>>a>>b>>c>>d>>e;
    a=a/3;b=b+a;e=e+a;
    b=b/3;c=c+b;a=a+b;
    c=c/3;d=d+c;b=b+c;
    d=d/3;e=e+d;c=c+d;
    e=e/3;a=a+e;d=d+e;
    cout<<setw(5)<<a<<setw(5)<<b<<setw(5)<<c<<setw(5)<<d<<setw(5)<<e; 
}