from up: 东直门老K
链表一对一
栈:1是先放进去的,但是最后一个出来的
队列:先买票先走,后买后走
树:下属
图:多对多
串:String集合的,高效存储
为什么要这样,这样一样的就不用再开一个数组存他了
串用二维数组来存
在串里不存在就创建
字符串最后是0
字符串映射下标。
idx为全局
p=son[p][u]儿子变成父亲
cnt统计字符串数量
#include <iostream> #include <string> using namespace std; const int N=100010; int tree[N][26],idx,cnt[N]; void k(string s) { int p=0; for(int i=0;s[i];i++) { int u=s[i]-'a'; if(!tree[p][u]) tree[p][u]=++idx; p=tree[p][u]; } cnt[p]++; } int hey(string s) { int p=0; for(int i=0;s[i];i++) { int u=s[i]-'a'; if(!tree[p][u]) return 0; p=tree[p][u]; } return cnt[p]; } int main() { string s,s1; int m; cin>>m; while(m--) { cin>>s>>s1; if(s=="I") { k(s1); } else { cout<<hey(s1)<<endl; } } return 0; } //这里填你的代码^^ //注意代码要放在两组三个点之间,才可以正确显示代码高亮哦~ 作者:线段树RE自动机 链接:https://www.acwing.com/activity/content/code/content/6931871/ 来源:AcWing 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
栈的底层数组或链表
栈方法
在加一个top()方法,弹出栈顶
对列方法
队列的pop()
函数通常用于从队列中删除并返回队首的元素。还要返回