Title Description
Set a, b, c are numbers between 0 and 9, abc, bcc two three-digit, and has: abc + bcc = 532. Seeking to satisfy all the conditions a, b, c of the value.
Enter a description:
Entitled without any input.
Output Description:
Please all output values a, b, c satisfies the condition the subject. Separated by a space between a, b, c. Each output per line.
Problem-solving ideas
First, brute force
Directly through the loop to find qualified a, b, c
Note that the initial conditions, a, b, respectively, as the hundreds digit, so from a traversing.
1 #include <stdio.h> 2 int main() 3 { 4 int a,b,c; 5 for(int a = 1;a<=9;a++) 6 for(int b = 1;b<=9;b++) 7 for(int c = 0;c<=9;c++) 8 if(a*100+b*10+c + b*100+c*10+c == 532) 9 printf("%d %d %d",a,b,c); 10 11 }
Second, when I solve problems, not violent method used, but the use of the characteristics of the problem directly calculate the answer.
abc + bcc = 532
Counting from the single digits, c = 1 c = 6 or maybe only cases
Bitwise discussed separately, not need to traverse! Direct negative case c = 6, i.e., the calculated value a, b, c of.