蜻蜓FM笔试总结


#include <iostream>
#include <fstream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>

using namespace std;

vector<int> len;

struct node{
	int data;
	struct node *left;
	struct node *right;
};

int isruledtree(node* root,int length){
	if(root!=NULL){	
		if((root->left==NULL)&&(root->right==NULL)){	//叶节点
			len.push_back(length);
		}
		else{
			isruledtree(root->left,length+1);
			isruledtree(root->right,length+1);
		}
	}
	return 0;
}




int main(){
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
	struct node a,b,c,d,e;
	a.data=5;
	a.left=&b;
	a.right=&c;
	b.data=3;
	b.left=&d;
	b.right=&e;
	c.data=10;
	c.left=NULL;
	c.right=NULL;
	d.data=2;
	d.left=NULL;
	d.right=NULL;
	e.data=3;
	e.left=NULL;
	e.right=NULL;
	isruledtree(&a,0);
	for(vector<int>::iterator it=len.begin();it!=len.end();++it){
		printf("%d",*it);
	}
}

遍历二叉树时,叶子到根节点的距离怎么计算


两台主机传输一个二叉树,怎么编解码

一个100亿个整形数字的文件,取文件中的中位数,内存不超过512MB。

快速排序的空间复杂度

死锁是针对什么情况

一个递归函数的时间复杂度问题

快速排序、堆排序的空间复杂度

制作蜻蜓FM爬虫,可参考以下步骤: ### 1. 构建请求URL 基于音频文件的ID(id)、书籍ID(bookid)以及必要的查询参数来构建基础的请求URL。这些查询参数包括访问令牌(access_token)、设备ID(device_id)、蜻蜓FM用户ID(qingting_id)和时间戳(t)。示例代码如下: ```python import time # 假设这些变量已有值 bookid = "your_book_id" id = "your_audio_id" access_token = "your_access_token" qingting_id = "your_qingting_id" timestamp = str(round(time.time() * 1000)) data = f"/audiostream/redirect/{bookid}/{id}?access_token={access_token}&device_id=MOBILESITE&qingting_id={qingting_id}&t={timestamp}" base_url = "https://example.qingting.fm" # 替换为实际的基础URL request_url = base_url + data ``` ### 2. 发送HTTP请求 使用`requests`库向构建好的URL发送HTTP请求,获取相应的数据。示例代码如下: ```python import requests response = requests.get(request_url) if response.status_code == 200: content = response.text else: print(f"请求失败,状态码: {response.status_code}") ``` ### 3. 解析响应数据 根据响应数据的类型(如JSON、HTML等),使用相应的解析库进行解析。如果是JSON数据,可使用`json`库;如果是HTML数据,可使用`BeautifulSoup`库。示例代码如下: ```python import json from bs4 import BeautifulSoup # 假设响应是JSON数据 try: json_data = response.json() # 处理JSON数据 print(json_data) except ValueError: # 假设响应是HTML数据 soup = BeautifulSoup(response.text, 'html.parser') # 处理HTML数据 print(soup.prettify()) ``` ### 4. 数据存储 将解析后的数据存储到本地文件或数据库中。示例代码如下: ```python import csv # 假设要存储为CSV文件 if json_data: with open('qingting_data.csv', mode='w', newline='', encoding='utf-8') as file: writer = csv.DictWriter(file, fieldnames=json_data[0].keys()) writer.writeheader() for item in json_data: writer.writerow(item) ``` ### 5. 反爬虫处理 蜻蜓FM可能有反爬虫机制,可采取以下措施应对: - 设置请求头,模拟浏览器访问: ```python headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'} response = requests.get(request_url, headers=headers) ``` - 控制请求频率,避免过于频繁的请求: ```python import time time.sleep(1) # 每次请求间隔1秒 ``` ### 6. 异常处理 在代码中添加异常处理机制,确保爬虫在遇到异常时能正常运行。示例代码如下: ```python try: response = requests.get(request_url, headers=headers) response.raise_for_status() # 检查响应状态码 except requests.RequestException as e: print(f"请求出错: {e}") except Exception as e: print(f"发生其他错误: {e}") ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值