关于封装结构体
  • 板块学术版
  • 楼主DGFLSzfd
  • 当前回复9
  • 已保存回复12
  • 发布时间2024/8/22 10:08
  • 上次更新2024/10/4 14:56:56
查看原帖
关于封装结构体
981551
DGFLSzfd楼主2024/8/22 10:08

在看 OI wiki 中经常可以看到封装结构体,但是我不知道该怎么用,调用的时候编译就报错。

BDFS了很久也不知道怎么搞,求dalao指教。

这个是字典树的封装结构体

#include<bits/stdc++.h>
using namespace std;

int  n,m;
map<string,bool>mp;

struct trie
{
	int nex[100000][26], cnt;
	bool exist[100000];

	void insert(char *s,int l)
	{
		// 插入字符串
		int p=0;
		for (int i=0;i<l;i++)
		{
			int c=s[i]-'a';
			if(!nex[p][c]) nex[p][c]=++cnt;  // 如果没有,就添加结点
			p=nex[p][c];
		}
		exist[p]=1;
	}

	bool find(char *s,int l)    // 查找字符串
	{
		int p=0;
		for (int i=0;i<l;i++)
		{
			int c=s[i]-'a';
			if(!nex[p][c]) return 0;
			p=nex[p][c];
		}
		return exist[p];
	}
};

int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		string s;int len=s.size();
		tt.insert(s,len);
	}
	cin>>m;
	for(int i=0;i<m;i++)
	{
		string s;
		if(tt.find(s,s.size())==1)
		{
			if(!mp[s])
			{
				cout<<"OK\n";
				mp[s]=1;
			}
			else cout<<"REPEAT\n";
		}else cout<<"WRONG";
	}
		
}

运行然后就一堆报错

2024/8/22 10:08
加载中...