[刷题] 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 ...
随机推荐
- Android创建自定义Application
开发目的 创建一个自定义的MainApplication继承Application. 读取AndroidManifest.xml文件中Application节点的META-DATA数据.此处以ApiK ...
- 201871030116-李小龙 实验三 结对项目—《D{0-1}KP 实例数据集算法实验平台》项目报告
项目 内容 课程班级博客链接 https://edu.cnblogs.com/campus/xbsf/2018CST 这个作业要求链接 https://www.cnblogs.com/nwnu-dai ...
- JavaWeb 基础知识补充
软件架构 1. C/S: Client/Server 客户端/服务器端 * 在用户本地有一个客户端程序,在远程有一个服务器端程序 * 如:QQ,迅雷... ...
- git推送代码报错:fatal: The current branch master has no upstream branch. To push the current branch and set the remote as upstream
情景再现 远程新建仓库,然后本地 git bash执行以下代码 git init git add . git commit -m 'xxx' git remote add origin https:/ ...
- Parentheses Balance UVA - 673
You are given a string consisting of parentheses () and []. A string of this type is said to be corr ...
- 爬虫简介、requests 基础用法、urlretrieve()
1. 爬虫简介 2. requests 基础用法 3. urlretrieve() 1. 爬虫简介 爬虫的定义 网络爬虫(又被称为网页蜘蛛.网络机器人),是一种按照一定的规则,自动地抓取万维网信息的程 ...
- pickle json模块
pickle --- Python 对象序列化 通过pickle模块的序列化操作我们能够将程序中运行的对象信息保存到文件中去,永久存储. 通过pickle模块的反序列化操作,我们能够从文件中创建上一次 ...
- HttpContext访问的正确姿势
本文章转发自:https://www.cnblogs.com/tianqing/p/12570801.html 使用HttpContext的具体场景: 1. 在Controller层访问HttpCon ...
- 1.6.1- HTML中ul元素无序列表的使用
无序列表的各个列表项之间没有顺序级别之分,是并列的,语法如下: <ul> <li>列表项1</li> <li>列表项2</li> <l ...
- VScode 使用提示
vscode 配置xdebug参考 vscode配置phpxdebug 未完,待续!