Blue Bridge Cup age coincidence

Source: Internet
Author: User

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;



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.