Interesting three-digit number
(0319)Time limit (ms): 65535 submission:158 accepted:62 Description has such a set of numbers, each group consists of three three-bit numbers, and the three numbers 1~9 have and only once, What's more special is that in these three numbers, two smaller numbers are added equal to another number (such as 124 659 783). Your task is to find all the groups that meet the above criteria (appear in groups and in ascending order (between each group in ascending order of the first element). For one of these groups, three numbers are sorted in ascending order). Inputno input output outputs all groups that satisfy the test instructions (a space between three numbers per group). Sample Input
Sample Output124 659 783125 739 864| | |-------ellipsis | |216 738 954218 349 567| | | | | Hint source computer Science and Technology major 2008 program design contest
1#include <iostream>2#include <algorithm>3 using namespacestd;4 intMain ()5 {6 inta[9]={1,2,3,4,5,6,7,8,9},b,c,d;7 while(Next_permutation (a,a+9))8 {9b=a[0]* -+a[1]*Ten+a[2];Tenc=a[3]* -+a[4]*Ten+a[5]; Oned=a[6]* -+a[7]*Ten+a[8]; A if(b+c==d&&b<=c) - { -cout<<b<<' '<<c<<' '<<d<<Endl; the } - } - return 0; -}
Note: B>c break is not correct, 231 987 654 the next permutation 234 156 789 terminates the loop, which is obviously incorrect.
Swust OJ interesting three-digit (0319)