当前位置: 首页 > wzjs >正文

视频网站seo怎么做软服业营收破334亿

视频网站seo怎么做,软服业营收破334亿,crm排名,深圳网站建设公司多少钱文章目录 题目输入格式输出格式输入样例输出样例 题解解题思路完整代码 编程练习题目集目录 题目 Given a tree, you are supposed to list all the leaves in the order of top down, and left to right. 输入格式 Each input file contains one test case. For each case, …

文章目录

  • 题目
    • 输入格式
    • 输出格式
    • 输入样例
    • 输出样例
  • 题解
    • 解题思路
    • 完整代码

编程练习题目集目录

题目

  Given a tree, you are supposed to list all the leaves in the order of top down, and left to right.

输入格式

  Each input file contains one test case. For each case, the first line gives a positive integer N ( ≤ 10 ) N (≤10) N(10) which is the total number of nodes in the tree − − -- and hence the nodes are numbered from 0 0 0 to N − 1 N−1 N1. Then N N N lines follow, each corresponds to a node, and gives the indices of the left and right children of the node. If the child does not exist, a " − " "-" "" will be put at the position. Any pair of children are separated by a space.

输出格式

  For each test case, print in one line all the leaves’ indices in the order of top down, and left to right. There must be exactly one space between any adjacent numbers, and no extra space at the end of the line.

输入样例

8
1 -
- -
0 -
2 7
- -
- -
5 -
4 6

输出样例

4 1 5

题解

解题思路

在这里插入图片描述
  找到树的根结点,根据树的根结点以及其它一系列结点构建树,按照从上到下,从左到右的顺序(层次遍历)输出这棵树的叶子结点。

完整代码

#include <iostream>         // 包含标准输入输出流库
#include <queue>            // 包含队列数据结构库using namespace std;        // 使用标准命名空间#define MaxN  10            // 定义最大节点数量// 定义二叉树节点结构
struct TreeNode
{int Data;           // 节点存储的数据int Left;           // 左子节点的索引,若无左子节点则为-2int Right;          // 右子节点的索引,若无右子节点则为-2
} TN[MaxN];             // TN[]为全局变量,存储所有节点信息,最多MaxN个节点int buildTree(TreeNode T[], int n);         // 构建二叉树,并返回根节点索引
void Traversal(int root);                   // 层序遍历二叉树,并输出叶节点值int main(void)
{int N, root;                            // N表示树的节点数量,root表示根节点索引cin >> N;root = buildTree(TN, N);                // 构建树并获取根节点索引Traversal(root);                        // 层序遍历并输出叶节点值return 0;
}// 构建二叉树
int buildTree(TreeNode T[], int n)
{int i, check[MaxN];                  // 检查数组,用于标记是否为子节点char left, right;                    // 用于存储左右子节点的输入字符if (n == 0) {                        // 如果节点数量为0,返回-2表示空树return -2;}for (i = 0; i < n; i++) {           // 初始化所有节点,初始时假设所有节点都不是子节点check[i] = -1;                  // -1表示非子节点TN[i].Data = i;                 // 每个节点的编号即为自己的数据}for (i = 0; i < n; i++) {           // 根据输入构建树cin >> left >> right;           // 输入当前节点的左右子节点信息if (left != '-') {                  // 如果有左子节点T[i].Left = left - '0';         // 将字符转换为索引check[T[i].Left] = 1;           // 标记左子节点对应的索引为子节点}else {T[i].Left = -2;                 // 表示无左子节点}if (right != '-') {                 // 如果有右子节点T[i].Right = right - '0';       // 将字符转换为索引check[T[i].Right] = 1;          // 标记右子节点对应的索引为子节点}else {T[i].Right = -2;                // 表示无右子节点}}// 查找根节点(未被标记为子节点的节点)for (i = 0; i < n; i++) {if (check[i] == -1) break;          // 找到根节点}return i;                               // 返回根节点索引
}
// 层序遍历二叉树并输出叶节点值
void Traversal(int root)
{queue<struct TreeNode> Q;               // 定义一个队列用于层序遍历struct TreeNode T;                      // 临时存储队列中的节点if (root == -2) {                       // 如果根节点不存在,直接返回return;}Q.push(TN[root]);                       // 将根节点入队int flag = 0;                           // 标志变量,用于控制输出格式while (!Q.empty()) {                    // 当队列非空时T = Q.front();                      // 取出队列头部节点Q.pop();                            // 出队if (T.Left == -2 && T.Right == -2) {        // 如果当前节点是叶节点if (flag == 1) cout << " ";             // 如果不是第一个叶节点,输出空格else flag = 1;                          // 标记已经输出过叶节点printf("%d", T.Data);             // 输出叶节点的值}if (T.Left != -2) {Q.push(TN[T.Left]);                     // 如果有左子节点,将左子节点入队}if (T.Right != -2) {                        // 如果有右子节点,将右子节点入队Q.push(TN[T.Right]);}}
}
http://www.dtcms.com/wzjs/352014.html

相关文章:

  • 深圳做网站的公司 cheungdom网络营销的概念和特点
  • 北京网站开开发公司网站开发建站
  • 山东建设厅网站是什么肇庆网站搜索排名
  • 做教育网站销售的好吗网络营销的推广方法
  • 建设传奇私服发布网站西安竞价托管代运营
  • 旅游网站开发背景百度推广怎么登陆
  • 上海城建建设官方网站今日头条十大新闻最新
  • 网站建设html新闻联播直播 今天
  • 做网站横幅的图片现在推广什么app最挣钱
  • 优仔电话手表网站网站数据分析
  • 海兴做网站价格怎么做百度网页推广
  • 做网站一个程序员够吗网络营销所学课程
  • 网站菜单素材互联网电商平台有哪些
  • 个人备案的网站可以卖东西么口碑营销策略有哪些
  • 网页简单模板下载网站seo专员招聘
  • 企业网站模板 讲湖南岚鸿2023免费网站推广大全
  • 青海旅游网站建设方案网站推广优化网址
  • 网站创建后台关键词优化需要从哪些方面开展?
  • 户外运动网站程序网站注册账号
  • 游戏网站建设平台百度指数搜索热度
  • 商务网站建设综合实训报告南宁seo排名收费
  • 仙桃网站制作网站设计计算机培训课程
  • 广东网站建设工作关键词优化公司如何选择
  • php手机网站开发天津百度seo代理
  • 学做网站如何创业如何策划一个营销方案
  • web前端就是做网站么企业短视频推广
  • css图片边框国外网站关键词权重
  • 南京旅游网站建设公司竞价排名推广
  • 梁山做网站的公司百度搜索引擎优化的方法
  • 惠州响应式网站哪家好百度竞价点击软件奔奔