当前位置:网站首页>B2020 points candy
B2020 points candy
2022-07-03 14:51:00 【Dega Altman】
Divide candy
Title Description
In a kindergarten , Yes 5 5 5 The numbers of the children are 1 , 2 , 3 , 4 , 5 1,2,3,4,5 1,2,3,4,5 They sat around a round table in their numbered order . They have some candy on them , Now they play a candy game . from 1 1 1 Children begin to , Divide your candy into 3 3 3 Share ( If there's extra candy , Just eat it immediately ), Keep one for yourself , The other two will be given to the two children next to him . next 2 , 3 , 4 , 5 2,3,4,5 2,3,4,5 Children No. 1 also do this . After the round , How many sweets are there in each child's hand .
Input format
a line , 5 5 5 Two separated by spaces int Positive integer in range , At the beginning of the game 1 , 2 , 3 , 4 , 5 1,2,3,4,5 1,2,3,4,5 The number of sweets in children's hands .
Output format
2 2 2 That's ok , The first 1 1 1 Lines are separated by a space 5 5 5 It's an integer , It means after a round of game 1 , 2 , 3 , 4 , 5 1,2,3,4,5 1,2,3,4,5 The number of sweets in children's hands . The first 2 2 2 The row is an integer , Indicates the total number of sweets eaten during a round of the game .
Examples #1
The sample input #1
8 9 10 11 12
Sample output #1
11 7 9 11 6
6
Ideas
No difficulty , Just calculate according to the meaning of the title , If you don't understand , You can leave me a message below .
Code
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int r[5];
int total = 0;
for (int i = 0; i < 5; i++) {
cin >> r[i];
}
for (int i = 0; i < 5; i++) {
total += r[i] % 3;
if (i == 4) {
r[0] += r[i] / 3;
}
else {
r[i + 1] += r[i] / 3;
}
if (i == 0) {
r[4] += r[i] / 3;
}
else {
r[i-1] += r[i] / 3;
}
r[i] /= 3;
}
for (int i = 0; i < 5; i++) {
cout << r[i]<< " ";
}
cout << endl << total << endl;
return 0;
}

边栏推荐
- tonybot 人形機器人 紅外遙控玩法 0630
- retrofit
- 4-33--4-35
- Zzuli:1052 sum of sequence 4
- Zzuli:1048 factorial table
- My QT learning path -- how qdatetimeedit is empty
- Vs+qt application development, set software icon icon
- C language memory function
- 零拷贝底层剖析
- Zhejiang University Edition "C language programming (4th Edition)" topic set reference ideas set
猜你喜欢

On MEM series functions of C language

Dllexport and dllimport
![[ue4] geometry drawing pipeline](/img/30/9fcf83a665043fe57389d44c2e16a8.jpg)
[ue4] geometry drawing pipeline

QT program font becomes larger on computers with different resolutions, overflowing controls

复合类型(自定义类型)

远程服务器后台挂起 nohup

链表有环,快慢指针走3步可以吗

Qt development - scrolling digital selector commonly used in embedded system

表单文本框的使用(一) 选择文本

Qt—绘制其他东西
随机推荐
Common shortcut keys in PCB
Zzuli:1049 square sum and cubic sum
提高效率 Or 增加成本,开发人员应如何理解结对编程?
[engine development] rendering architecture and advanced graphics programming
C language memory function
[graphics] adaptive shadow map
Get permissions dynamically
链表有环,快慢指针走3步可以吗
tonybot 人形机器人 首次开机 0630
NOI OPENJUDGE 1.4(15)
Sub GHz wireless solution Z-Wave 800 Series zg23 SOC and zgm230s modules
Tonybot Humanoïde Robot Infrared Remote play 0630
Puzzle (016.3) is inextricably linked
Zzuli:1056 lucky numbers
How to color ordinary landscape photos, PS tutorial
[combinatorics] permutation and combination (set combination, one-to-one correspondence model analysis example)
Tonybot humanoid robot starts for the first time 0630
Find books ()
Yolov5进阶之八 高低版本格式转换问题
创业团队如何落地敏捷测试,提升质量效能?丨声网开发者创业讲堂 Vol.03