NetEase 2017 School Recruit program: Calculate candy

Source: Internet
Author: User

A,b,c Three people are good friends, everyone has some candy in their hands, we do not know how many of them each have the specific number of candies, but we know the following information:
A-A, b-c, A + b, B + C. These four values. Each letter represents the number of candies each person has.
Now it's time to figure out how many candies are in each person's hand, namely a,b,c, through these four numbers. There is a guaranteed maximum of only one set of integers a,b,c satisfy all the set conditions.

Input Description:
Enter as a row, a total of 4 integers, respectively a-b,b-c,a + b,b + C, separated by a space. The range is between 30 and 30 (closed interval).



Output Description:
The output is a row, if there is a satisfied integer a,b,c is output a,b,c sequentially, separated by a space, no space at the end of the line. If there is no such integer a,b,c, the output no

Input Example:
1-2 3 4

Output Example:
2 1 3

Direct calculation
Why is Java not the same as C + +?
#include <iostream>using namespacestd;intMain () {intm1,m2,m3,m4; CIN>> M1 >> m2 >> m3 >>M4; intA = (m1 + m3)/2; intB = (M3-M1)/2; intC = (m4-m2)/2; if(A-B = M1 && A + = = M3 &&B-c = = M2 && b+c = =M4) {cout<< A <<" "<< b<<" "<< C <<Endl; }        Else{cout<<"No"<<Endl; }         return 0;}

The following array is out of bounds

ImportJava.util.Scanner; Public classMain { Public Static voidMain (string[] args) {Scanner in=NewScanner (system.in); inta,b,c,d; intA,b,c;  while(In.hasnext ()) {a=In.nextint (); b=In.nextint (); C=In.nextint (); D=In.nextint (); A= (a+c)/2; B= (c-a)/2; C= (d-b)/2; if((a-b==a) && (b-c==b) && (a+b ==c) && (b+c==d)) System.out.println (A+ "" +b+ "" +C); ElseSystem.out.println ("No"); }    }}




NetEase 2017 School Recruit program: Calculate candy

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.