[刷题] PTA 6-7 统计某类完全平方数
要求:
实现一个函数,判断任一给定整数N
是否满足条件:它是完全平方数,又至少有两位数字相同,如144、676等。
函数接口定义: int IsTheNumber ( const int N );
其中N是用户传入的参数。如果N满足条件,则该函数必须返回1,否则返回0。
1 #include <stdio.h>
2 #include <math.h>
3
4 int IsTheNumber ( const int N );
5
6 int main()
7 {
8 int n1, n2, i, cnt;
9 scanf("%d %d", &n1, &n2);
10 cnt = 0;
11 for ( i=n1; i<=n2; i++ ) {
12 if ( IsTheNumber(i) )
13 cnt++;
14 }
15 printf("cnt = %d\n", cnt);
16 return 0;
17 }
18
19 int IsTheNumber ( const int N ){
20 int n, p, t;
21 t = N;
22 n = (int)sqrt(N);
23 if( N == n*n ){
24 int a[10] = {0};
25 while(t){
26 p = t%10;
27 if(!a[p]){
28 a[p] = 1;
29 }else{
30 return 1;
31 }
32 t /= 10;
33 }
34 }
35 return 0;
36 }
[刷题] PTA 6-7 统计某类完全平方数的更多相关文章
- pta 6-7 统计某类完全平方数 (20分)
6-7 统计某类完全平方数 (20分) 本题要求实现一个函数,判断任一给定整数N是否满足条件:它是完全平方数,又至少有两位数字相同,如144.676等. 函数接口定义: int IsTheNumber ...
- PTA基础编程题目集6-7 统计某类完全平方数 (函数题)
本题要求实现一个函数,判断任一给定整数N是否满足条件:它是完全平方数,又至少有两位数字相同,如144.676等. 函数接口定义: int IsTheNumber ( const int N ); 其中 ...
- [刷题] PTA 查验身份证
题目: 7-63 查验身份证 (15 分) 一个合法的身份证号码由17位地区.日期编号和顺序编号加1位校验码组成.校验码的计算规则如下: 首先对前17位数字加权求和,权重分配为:{7,9,10,5, ...
- [刷题] PTA 02-线性结构3 Reversing Linked List
链表逆序 1 #include<iostream> 2 #include<stdio.h> 3 #include<algorithm> 4 using namesp ...
- [刷题] PTA 03-树3 Tree Traversals Again
用栈实现树遍历 1 #include<stdio.h> 2 #include<string.h> 3 #define MAXSIZE 30 4 5 int Pre[MAXSIZ ...
- [刷题] PTA 7-61 找最长的字符串
程序: 1 #include<stdio.h> 2 #include<string.h> 3 #define N 81 4 5 int main() { 6 char ch[N ...
- [刷题] PTA 7-62 切分表达式 写个tokenizer吧
我的程序: 1 #include<stdio.h> 2 #include<string.h> 3 #define N 50 4 char token[]= {'+','-',' ...
- [刷题] PTA 04-树4 是否同一棵二叉搜索树
程序: 1 #include <stdio.h> 2 #include <stdlib.h> 3 typedef struct TreeNode *Tree; 4 struct ...
- [刷题] PTA 03-树2 List Leaves
程序: 1 #include <stdio.h> 2 #include <queue> 3 #define MaxTree 20 4 #define Null -1 5 usi ...
随机推荐
- 结对编程_stage1
项目 内容 这个作业属于哪个课程 2021春季软件工程(罗杰 任健) 这个作业的要求在哪里 结对项目-第一阶段 我在这个课程的目标是 从实践中学习软件工程相关知识(结构化分析和设计方法.敏捷开发方法. ...
- Spring Boot 2.4 新特性,全新的Cron表达式处理机制
说起 cron 表达式大家一定不陌生,我们常用来作为定时任务执行策略规则. 在 Spring Boot 框架中 cron 表达式主要配合 @Scheduled 注解在应用程序中使用. 在 Spring ...
- pandas(1):Pandas文件读取——read_excel()
目录 一.函数原型 二.功能说明 三.常用参数说明 四.总结 一.函数原型 pd.read_excel(io, sheet_name=0, header=0, names=None, index_co ...
- [ERROR]: gitstatus failed to initialize.
1 问题描述 Manjaro升级后,zsh的主题p10k出现的问题. Your git prompt may disappear or become slow. Run the following c ...
- 8. vue给标签动态绑定title
在利用vue开发时,如果标签宽度比较小,我们需要利用overflow:hidden;text-overflow:ellipsis;white-space: nowrap;对其进行隐藏,但隐藏后如何读其 ...
- Box UVA - 1587
Ivan works at a factory that produces heavy machinery. He has a simple job - he knocks up wooden box ...
- Django中的CBV视图
Web 开发是一项无聊而且单调的工作,特别是在视图功能编写方面更为显著.为了减少这种痛苦,Django植入了视图类这一功能,该功能封装了视图开发常用的代码,无须编写大量代码即可快速完成数据视图的开发, ...
- k8s job 控制器
Job控制器可以执行3种类型的任务 1)一次性任务 2)串式任务 spec.completions 3)并形式任务 spec.parallelism 默认Job执行后,不会自动删除,需要手动删除,例如 ...
- 你好,FFMPEG 可视化
你好,FFMPEG 可视化 给大家看看我现在的玩具: 它有哪些功能呢?如你所见,不止于此 1. 视频录制 暂时只能录制视频,音频无法录制 FFMPEG.exe 暂时只支持视频,音频录制需要下载额外的工 ...
- Vulkan移植GpuImage(四)从D到O的滤镜
现把D到O的大部分滤镜用vulkan的ComputeShader实现了,列举其中一些有点特殊的说明. GaussianBlurPosition 指定区域高斯模糊 没有按照GPUImage里的方式实现, ...