test·B·Summary

这是一个C++实现的字典字符串匹配算法。程序读取字典文件,然后处理一个输入字符串,通过遍历字符串并比较与字典中单词的匹配情况,计算出最少的插入删除操作次数。
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
void read(int& x)
{
	x = 0;
	char c = getchar();
	bool flag = 0;
	while(c<'0'||c>'9')
	{
		if(c=='-')flag=1;
		c = getchar();
	}
	while(c>='0'&&c<='9')
	{
		x = x*10+c-'0';
		c =getchar();
	}
	if(flag)x = -x;
}
int n,m;
char s[305],dict[605][305];
int len[605];
int dp[305];
int cal(int pos,int ch)
{
	int cur = 1,ret = 0;
	while(1)
	{
		while(pos<=m&&cur<=len[ch]&&dict[ch][cur]==s[pos])pos++,cur++;
		if(cur>len[ch])return ret;
		pos++,ret++;
		if(pos>m)return -1;
	}
}
int main()
{
#define AC
#ifdef AC
	freopen("dictionary.in","r",stdin);
	freopen("dictionary.out","w",st
# 优先级名称映射 priority_name_map = { 'other_priority': '其它优先级', 'NONE': '无优先级', 'summary': '总计' } # 初始化结果列表 b = [] # 显式定义测试类型顺序(固定顺序) test_types_order = [ 'security_over_permit', 'security_sql_inject', 'function' ] # 动态获取项目顺序 projects_order = list(a.keys()) for test_type in test_types_order: if not any(test_type in project_data for project_data in a.values()): continue handled_projects = set() for project in projects_order: if project not in a or test_type not in a[project]: continue test_data = a[project][test_type] project_handled = project in handled_projects priorities = [p for p in ['P1', 'P2', 'P3'] if p in test_data] others = [k for k in test_data if k not in priorities + ['summary']] group_rows = [] show_test_type = not handled_projects # 仅在该测试类型的第一个项目首行显示 show_project = not project_handled # 仅在该项目的首行显示 for idx, key in enumerate(priorities + others): data = test_data[key] priority_name = priority_name_map.get(key, key) row = [ '*', test_type if (show_test_type and idx == 0) else '', project if (show_project and idx == 0) else '', priority_name, data['total_api'], data['run_api'], data['total_case'], data['run_case'] ] group_rows.append(row) summary = test_data['summary'] summary_row = [ '*', '', '', '总计', summary['total_api'], summary['run_api'], summary['total_case'], summary['run_case'] ] group_rows.append(summary_row) b.extend(group_rows) handled_projects.add(project) 实现功能及逻辑不变,可以简化代码吗,同时将变量名易懂
03-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

真·skysys

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值