考研编程: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);
}
相关推荐
LVerrrr6 小时前
Missashe考研日记-day21
学习·考研
LVerrrr1 天前
Missashe考研日记-day20
学习·考研
西贝爱学习2 天前
考研408参考用书:计算机组成原理(唐朔飞)介绍,附pdf
考研·pdf
LVerrrr2 天前
Missashe考研日记-day18
学习·考研
会讲英语的码农2 天前
什么叫“架构”
考研·架构·硬件架构
不爱吃于先生2 天前
计算机考研一战上岸宁波大学经验分享
经验分享·考研
碧海蓝天2622 天前
25级总分413数学一142专业124东南大学820考研经验电子信息通信工程,真题,大纲,参考书。
考研·信息与通信·信号处理
L73S373 天前
MySQL数据类型
mysql·考研·学习方法
西电研梦4 天前
难度偏低,25西电人工智能学院821、833、834考研录取情况
人工智能·考研·面试·西安电子科技大学·考研录取
Heorine5 天前
408 计算机网络 知识点记忆(8)
计算机网络·考研