考研编程:10.11 回文数 水仙花 生成一定范围内的随机数 求二叉树宽度

回文数
cpp 复制代码
#include <stdio.h>

int main(){
	 int a,b,c=0,sum;
	 scanf("%d",&a);
	 b=a;
	 while(b!=0){
	 	c = b%10 + c*10;
	 	b = b/10;
	 }
	 if(c==a){
	 	printf("yes");
	 }
	return 0;
}
水仙花
cpp 复制代码
#include <stdio.h>
#include <math.h>
int main(){
	 int a,b,c=0,sum;
	 scanf("%d",&a);
	 b = a;
	 while(b>0){
	 	c = c + pow(b%10,3);
		 b = b/10; 
	 }
	 if(c==a){
	 	printf("yes");
	 }
	return 0;
}
生成一定范围内的随机数

C语言:生成随机数(并非固定的随机数)------rand()、srand()_c语言生成随机数-CSDN博客

cpp 复制代码
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(){
	int a;
	srand(unsigned(time(NULL)));
	a = (rand()%100)+1;
	printf("%d",a);
	return 0;
}
求二叉树的最大宽度

1.队列修改:修改了rear和front的指代意思,当front指向一个数组下标的时候的意思是这个元素已经从队列中出去了

2.这个二叉树的插入,我们用户的输入就是输入一个带#号的二叉树的先序序列如图

cpp 复制代码
void List(TreeNode* T){
	q[++rear] = T;
	int max = 0;
	int sum[100]={0};
	int level = 1;
	int r = 0;
	while(!IsEmpty()){
		TreeNode *p = q[++front]; 
		if(p->lChild!=NULL){
			q[++rear]=p->lChild;
		}
		if(p->rChild!=NULL){
			q[++rear]=p->rChild;
		}
		sum[level]++;
		printf("判断之前%c r=%d e=%d b=%d level=%d\n",p->data,r,rear,front,level);
        if(front==r){
        	level++;
        	r = rear;
		}
		printf(" %c r=%d e=%d b=%d level=%d\n",p->data,r,rear,front,level);
	}
	printf("\n");
	for(int i=1;sum[i]!=0;i++){
		if(sum[i]>max){
			max = sum[i];
		}
	}
    printf("%d",max);
}
相关推荐
元亓亓亓12 小时前
考研408--day2--组成原理--进制&定点数&符号拓展
考研·408·组成原理
立志成为大牛的小牛1 天前
数据结构——三十七、关键路径(王道408)
数据结构·笔记·程序人生·考研·算法
岑梓铭2 天前
《考研408数据结构》第六章(5.5树的应用)复习笔记
数据结构·笔记·考研·408·ds
立志成为大牛的小牛2 天前
数据结构——三十六、拓扑排序(王道408)
数据结构·学习·程序人生·考研·算法
十五学长2 天前
程序设计C语言
c语言·开发语言·笔记·学习·考研
岑梓铭3 天前
《考研408数据结构》第七章(6.1~6.3图的概念、存储方式、深/广度遍历)复习笔记
数据结构·笔记·考研·算法·图论·408·ds
蒙奇D索大3 天前
【计算机网络】408考研核心考点:物理层设备(中继器/集线器)深入解析
经验分享·笔记·计算机网络·考研·改行学it
元亓亓亓4 天前
考研408--计算机网络--day2--性能指标&分层结构&OSI&TCP/IP
计算机网络·考研
WebGIS开发5 天前
福建师范大学26地学考研指南
考研·26考研·福建师范大学·地学考研指南·地学考研
蒙奇D索大5 天前
【计算机网络】考研408计算机网络:传输介质(导向/非导向)考点梳理
笔记·计算机网络·考研·408·改行学it