unordered_set set1; 构造
unordered_set set2(set1); 拷贝构造
set1.count(2); 出现次数
unordered_set 无序 set 容器可以和字符串哈希有着类似的作用 也可以一起用

例题acwing1460

[unordered_set做法] [c++]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include<bits/stdc++.h>
using namespace std;

string str;
int n,l,r;

bool check(int mid)
{
unordered_set<string> hash;
for(int i=0;i+mid-1<str.size();i++)
{
auto s1=str.substr(i,mid);
if(hash.count(s1)) return false; //查找出现次数 如果重复直接寄
hash.insert(s1);
}
return true;
}
int main()
{
cin>>n;
cin>>str;
l=1,r=n;
while(l<r)
{
int mid=(l+r)>>1;
if(check(mid)) r=mid;
else l=mid+1;
}
cout<<l<<endl;
return 0;

}