Pta-c-4-7 statistics A class of complete squares (20 points)

Source: Internet
Author: User

4-7 statistic a class of complete squares (20 points)

The subject requires the implementation of a function that determines whether any given integer N satisfies the condition: it is a total square number, and at least two digits are the same, such as 144, 676, and so on.

function Interface Definition:
int IsTheNumber ( const int N );

These N are the parameters that the user passed in. If the N condition is met, the function must return 1, otherwise 0 is returned.

Example of a referee test procedure:
#include <stdio.h>#include <math.h>int IsTheNumber ( const int N );int main(){    int n1, n2, i, cnt;    scanf("%d %d", &n1, &n2);    cnt = 0;    for ( i=n1; i<=n2; i++ ) {        if ( IsTheNumber(i) )            cnt++;    }    printf("cnt = %d\n", cnt);    return 0;}/* 你的代码将被嵌在这里 */
Input Sample:
105 500
Sample output:
cnt = 6


int isthenumber (const int N) {int n,m,temp;m=n;n = (int) sqrt (N); if (n*n==m) {int num[10]= {0};<span style= "White-space: Pre "></span>//here the length of NUM should be defined as 10 because the number of digits passed in the integer may be 0~~9 instead of the number of bits passed in. while (m>0) {<span style= "White-space:pre" ></span>//the number on each of the n's, the corresponding array is self-added if there is an array element equal to 2 Description at least 2 digits on the same temp = m%10;for (int i=0; i<=9;i++) {if (temp==i) {num[i]++;if (num[i]==2) {return 1;}}} m/=10;} return 0;} return 0;}


Pta-c-4-7 statistics A class of complete squares (20 points)

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.