简单搜索--DFS--Find The Multiple

简单搜索–DFS–Find The Multiple

Description
给定一个正整数n,编写一个程序来找出一个n的非零倍数m,它的十进制表示法仅包含数字0和1。你可以假设n不大于200,并且对应的m不包含100小数位数。

Input
输入文件可能包含多个测试用例。每一行包含一个值n(1<=n<=200)。包含零的行结束输入。

Output
对于输入中的n个值,打印一行,其中包含m的对应值。m的十进制表示不能包含超过100位数字。如果给定值n有多个解,则其中任何一个都是可接受的。

Sample Input
2
6
19
0
Sample Output
10
100100100100100100
111111111111111111

用DFS遍历,每次有两种情况x10或者x10+1
考虑这道题的范围,要用longlong

#include <iostream>
#include <cstdio><
pip install pandas openpyxl xlsxwriter tqdm import pandas as pd import re from tqdm import tqdm import os def filter_single_company_news(input_path, output_path, company_list): # === 1. 前置检查 === if not os.path.exists(input_path): raise FileNotFoundError(f"文件 {input_path} 不存在") # === 2. 加载公司列表 === with open(company_list, 'r', encoding='utf-8') as f: companies = [line.strip() for line in f if line.strip()] # === 3. 构建正则表达式 === escaped_companies = [re.escape(company) for company in companies] boundary_pattern = r'(?<![一-鿿a-zA-Z0-9])(?:{})(?![一-鿿a-zA-Z0-9])'.format('|'.join(escaped_companies)) cross_regex = re.compile( r'({}).*?({})'.format(boundary_pattern, boundary_pattern), flags=re.IGNORECASE ) # === 4. 分块处理(关键修复) === try: # 分块读取(添加 chunksize 参) chunks = pd.read_excel(input_path, engine='openpyxl', chunksize=10000) except Exception as e: raise ValueError(f"Excel文件读取失败: {str(e)}") filtered_dfs = [] for chunk in tqdm(chunks, desc="处理进度"): # === 列名检查 === if 'NewsContent' not in chunk.columns: raise KeyError("Excel文件中必须包含 'NewsContent' 列") # === 类型转换 === chunk['NewsContent'] = chunk['NewsContent'].astype(str) # === 检测函 === def check_multiple(text): matches = cross_regex.findall(text) if not matches: return False unique_companies = {m[0].lower() for m in matches} | {m[1].lower() for m in matches} return len(unique_companies) >= 2 # === 生成过滤掩码 === mask = chunk['NewsContent'].apply(lambda x: not check_multiple(x)) filtered_dfs.append(chunk[mask]) # === 5. 保存结果 === if filtered_dfs: final_df = pd.concat(filtered_dfs, ignore_index=True) final_df.to_excel(output_path, index=False, engine='xlsxwriter') print(f"处理完成!保留据量:{len(final_df)}条") else: print("警告:未处理任何据!") # === 使用示例 === if __name__ == "__main__": filter_single_company_news( input_path='sample.xlsx', output_path='filtered_news.xlsx', company_list='companies.txt' ) 以上为完整代码,运行到此处报错。 --------------------------------------------------------------------------- TypeError Traceback (most recent call last) ~\AppData\Local\Temp/ipykernel_14844/3787377892.py in filter_single_company_news(input_path, output_path, company_list) 20 # 分块读取(添加 chunksize 参---> 21 chunks = pd.read_excel(input_path, engine='openpyxl', chunksize=5000) 22 except Exception as e: D:\py\anaconda\lib\site-packages\pandas\util\_decorators.py in wrapper(*args, **kwargs) 310 ) --> 311 return func(*args, **kwargs) 312 TypeError: read_excel() got an unexpected keyword argument 'chunksize' During handling of the above exception, another exception occurred: ValueError Traceback (most recent call last) ~\AppData\Local\Temp/ipykernel_14844/3187432990.py in <module> 1 # === 使用示例 === 2 if __name__ == "__main__": ----> 3 filter_single_company_news( 4 input_path='sample.xlsx', 5 output_path='filtered_news.xlsx', ~\AppData\Local\Temp/ipykernel_14844/3787377892.py in filter_single_company_news(input_path, output_path, company_list) 21 chunks = pd.read_excel(input_path, engine='openpyxl', chunksize=5000) 22 except Exception as e: ---> 23 raise ValueError(f"Excel文件读取失败: {str(e)}") 24 25 filtered_dfs = [] ValueError: Excel文件读取失败: read_excel() got an unexpected keyword argument 'chunksize'
最新发布
03-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值