当前位置:网站首页>[day_040421] calculate candy
[day_040421] calculate candy
2022-07-26 06:11:00 【On the Bank of Anhe Bridge】
Calculate candy
Title source
Cattle from : Calculate candy
Title Description
A,B,C Three people are good friends , Everyone has some candy in his hand , We don't know how many sweets each of them has , But we know the following information :
A - B, B - C, A + B, B + C. These four values . Each letter represents the number of sweets each person has .
Now we need to calculate how many sweets each person has in his hand through these four values , namely A,B,C. There is guaranteed to be at most one set of integers A,B,C Meet all problem setting conditions .
Input description
Enter as one line , altogether 4 It's an integer , Respectively A - B,B - C,A + B,B + C, Space off . The range is -30 To 30 Between ( Closed interval ).
Output description
Output as a line , If there is an integer that satisfies A,B,C Then output... In sequence A,B,C, Space off , There is no space at the end of the line . If such an integer does not exist A,B,C, The output No
Example 1
Input
1 -2 3 4
Output
2 1 3
Thought analysis
- According to the method of solving ternary linear equations in Mathematics , Addition and subtraction , Work out separately A、B、C Value
- because B There is more than one solution , So we use two methods to find B Value comparison of , There is only one solution
- The number of candies owned by three people is greater than or equal to 0
Code display
#include<iostream>
using namespace std;
int main()
{
int n1, n2, n3, n4;
int a, b1, b2, c;
// Cycle through multiple data
while (cin >> n1 >> n2 >> n3 >> n4)
{
if (n3 < 0 || n4 < 0)
{
cout << "No";
continue;
}
// The number of sweets is not decimal
if ((n1 + n3) % 2 != 0 || (n2 + n4) % 2 != 0 || (n3 - n1) % 2 != 0 || (n4 - n2) % 2 != 0)\
{
cout << "No";
continue;
}
a = (n1 + n3) / 2;
b1 = (n2 + n4) / 2;
b2 = (n3 - n1) / 2;
c = (n4 - n2) / 2;
if (b1 != b2 || a < 0 || b1 < 0 || c < 0)
{
cout << "No";
}
else
{
cout << a << " " << b1 << " " << c;
}
}
}
边栏推荐
- PHP 多任务秒级定时器的实现方法
- 【Day06_0423】C语言选择题
- Talking about the practice of software defect management
- 分布式 | 实战:将业务从 MyCAT 平滑迁移到 dble
- 实习运维知识积累
- RNN循环神经网络
- How can machinery manufacturing enterprises do well in production management with the help of ERP system?
- TPS Motion(CVPR2022)视频生成论文解读
- 【pytorch】CNN实战-花朵种类识别
- Flex layout
猜你喜欢

Implementation of PHP multitask second timer

Knowledge precipitation I: what does an architect do? What problems have been solved

Convolutional neural network (IV) - special applications: face recognition and neural style transformation

Registration conditions for system integration project management engineer (intermediate level of soft exam) in the second half of 2022

The time complexity of two recursive entries in a recursive function

Flex layout

Age is a hard threshold! 42 years old, Tencent level 13, master of 985, looking for a job for three months, no company actually accepted!

Jz36 binary search tree and bidirectional linked list
![[the most complete and detailed] ten thousand words explanation: activiti workflow engine](/img/4c/2e43aef33c6ecd67d40730d78d29dc.png)
[the most complete and detailed] ten thousand words explanation: activiti workflow engine

【Day05_0422】C语言选择题
随机推荐
[Oracle SQL] calculate year-on-year and month on month (column to row offset)
基于消防GIS系统的智慧消防应用
【Day_05 0422】连续最大和
Operating steps for uninstalling the mobile app
How to divide the disks under the devices and drives in win10 new computer
Establishment of log collection and analysis platform-1-environment preparation
Knowledge precipitation I: what does an architect do? What problems have been solved
Workflow activiti5.13 learning notes (I)
【Day_06 0423】把字符串转换成整数
K. Link with Bracket Sequence I dp
Huawei cloud koomessage is a new marketing weapon in the hot public beta
Embedded sharing collection 15
【Day_03 0420】字符串中找出连续最长的数字串
What is spark serialization for?
Kingbasees SQL language reference manual of Jincang database (8. Functions (XI))
“子问题的递归处理”——判断两棵树是不是相同的树——以及 另一颗树的子树
【Day_03 0420】数组中出现次数超过一半的数字
Print linked list in reverse order
CV (1)- Introduction
VRRP principle and basic commands