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