1159 Structure of a Binary Tree (30 分)

这段代码展示了如何从包含'parent'关键字的字符串中,使用sscanf函数解析出两个整数,分别代表父节点和子节点的ID。通过查找字符串's32istheparentof11',程序将输出p1=32, p2=11。
摘要由CSDN通过智能技术生成

收获:深度从上往下计数,根节点深度为1;
高度从下往上计数,叶节点高度为1
高度从下往上计数
sscanf的使用

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<string>
#include<vector>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<unordered_map>
#include<map>
#include<queue>
using namespace std;
int main()
{
	int p1, p2;
	string s = "32 is the parent of 11";
	if(s.find("parent") != s.npos)
	{
	sscanf(s.c_str(), "%d is the parent of %d", &p1, &p2);
	printf("p1=%d,p2=%d", p1, p2);
	}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值