当前位置:网站首页>[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;
}
}
}
边栏推荐
- Distributed | practice: smoothly migrate business from MYCAT to dble
- Intelligent fire protection application based on fire GIS system
- Niuke network: TOPK problem of additive sum between two ordinal groups
- Taobao pinduoduo Tiktok 1688 Suning taote jd.com and other keyword search commodity API interfaces (keyword search commodity API interface, keyword search commodity list interface, classification ID s
- Practice operation and maintenance knowledge accumulation
- 漫谈软件缺陷管理的实践
- [Oracle SQL] calculate year-on-year and month on month (column to row offset)
- 【Day04_0421】C语言选择题
- 【2023杰理科技提前批笔试题】~ 题目及参考答案
- Convolutional neural network (IV) - special applications: face recognition and neural style transformation
猜你喜欢

VS中使用动态库

Leetcode:934. The shortest Bridge

【Day_06 0423】不要二

Solutions to the failure of copy and paste shortcut keys

数据库sql语言实战

Embedded sharing collection 15
![[Oracle SQL] calculate year-on-year and month on month (column to row offset)](/img/ee/59d050e03c2a4ba04de57df1322283.png)
[Oracle SQL] calculate year-on-year and month on month (column to row offset)

【Day05_0422】C语言选择题

Unity2d animator cannot create transition

Optical quantum milestone: 3854 variable problems solved in 6 minutes
随机推荐
Leetcode:940. How many subsequences have different literal values
VRRP protocol and experimental configuration
redis 哨兵集群搭建
Ganglia installation and deployment process
A company installs monitoring for each station: write code only to see employees?
【Day_03 0420】字符串中找出连续最长的数字串
Kingbasees SQL language reference manual of Jincang database (11. SQL statement: abort to alter index)
The number of weeks of Oracle last year and this year, with the start time and end time
【Day_04 0421】进制转换
[the most complete and detailed] ten thousand words explanation: activiti workflow engine
Mysql45 talks about transaction isolation: why can't I see it after you change it?
Convolutional neural network (III) - target detection
H. Take the Elevator 贪心
Convolutional neural network (II) - deep convolutional network: case study
Embedded sharing collection 14
Code Runner for VS Code,下载量突破 4000 万!支持超过50种语言
卸载手机自带APP的操作步骤
Recursive processing - subproblem
Jz36 binary search tree and bidirectional linked list
Kingbasees SQL language reference manual of Jincang database (7. Conditional expression)