本题要求实现一个函数,判断任一给定整数N
是否满足条件:它是完全平方数,又至少有两位数字相同,如144、676等。
函数接口定义:
1
| int IsTheNumber ( const int N );
|
其中N
是用户传入的参数。如果N
满足条件,则该函数必须返回1,否则返回0。
裁判测试程序样例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| #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; }
|
输入样例:
输出样例:
AC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| int IsTheNumber ( const int N ){ int n=N; int b; int number[10]={0}; int m=sqrt(n); if(m*m==n){ while(n){ b=n%10; number[b]++; n/=10; } for(int i=0;i<=9;i++){ if(number[i]>1) return 1; } } return 0; }
|
详解:本题要求实现一个函数,判断任一给定整数N是否满足条件:它是完全平方数,又至少有两位数字相同,如144、676等。_大道归简的博客-CSDN博客