[Huawei machine trial exercise] 58. Search for the number of homogeneous numbers.

Source: Internet
Author: User

[Huawei machine trial exercise] 58. Search for the number of homogeneous numbers.

Question

Description:

Find the number of homogeneous numbers between 1 and n. The homogeneous number is a set of numbers: it appears on the right side of the number of operators. For example, 5 is the number on the Right of 25, 25 is the number on the Right of 625, and 5 and 25 are homogeneous numbers.

Detailed description:

Interface Description
Prototype:

intSearchSameConstructNum(int n);

Input parameters:

Int n: finds all homogeneous numbers between 1 and n.

Return Value:

Int: Number of homogeneous numbers between 1 and n

Exercise phase:

Elementary

Code

/* ------------------------------------- * Date: 2015-07-05 * Author: SJF0115 * question: Number of homogeneous numbers * Source: Huawei machine trial exercise question author */# include <iostream> # include "OJ. h "# include <vector> # include <cmath> # include <algorithm> using namespace std;/* function: Find the number of homogeneous numbers between 1 and n. Input: int n: returns the number of all homogeneous numbers between 1 and n: int: 1 to n x/int SearchSameConstructNum (int n) {int square, tmp; int count = 0; for (int I = 1; I <= n; ++ I) {squ Are = I * I; tmp = I; while (tmp) {if (square % 10! = Tmp % 10) {break;} // if square/= 10; tmp/= 10;} // while if (tmp = 0) {++ count ;} // if} // for return count ;}

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.