Xiao Ming and his cousin go to the movies, some people ask their age. Xiao Ming said: This year is our lucky year ah. The four digits of my year of birth add up to just my age.
The same is true of cousin. Known this year is 2014, and, Xiao Ming said the age refers to the old.
Please infer and fill out the year of birth of Xiaoming.
This is a 4-bit integer, please submit the answer through the browser, do not fill in any superfluous content (for example, his cousin's birth year, or their age, etc.
Ideas:
2014-Xiaoming's Year of birth = = 4 digits of Xiaoming's birth
The number of ABCD4 represents the range of each digit a must be 1 or 2,
There are two answers to the results, the years long must be xiaoming, and the other
It's his cousin's.
Code:
#include <iostream>
using namespace std;
int main ()
{
int a,b,c,d;
for (a=1;a<3;a++) for (
b=0;b<10;b++) for (
c=0;c<10;c++) for (
d=0;d<10;d++)
{
if ( 2014-(a*1000+b*100+c*10+d) ==a+b+c+d)
cout<<a<<b<<c<<d<<endl;
}
return 0;