RT
已知c++ set插入和查询一个数都要 O(NlogN) 的复杂度。我的算法也是如此,读入字符串,判断在这个 set 里是否出现过,如果有,就插入,否则一个个枚举st1,st2,st3这样的字符串,如果可以插入,就插入,并输出改编后的字符串。
我即断了同步,也开了o2,咋还t呢
#include <iostream>
#include <set>
using namespace std;
typedef long long l;
set<string>s;
string hecheng(string st,l shu){
string h;
while(shu > 0){
h+=shu%10+48;
shu/=10;
}
return st+h;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
l n;
cin>>n;
for(l i=0;i<n;i++){
string st;
cin>>st;
l x=0;
if(s.count(st)==0){
cout<<"OK\n";
s.insert(st);
}else{
while(s.count(hecheng(st,x)) == 1){
x++;
}
string k=hecheng(st,x);
cout<<k<<"\n";
s.insert(k);
}
}
return 0;
}```
求大佬指教