Find
时间限制:1000MS 内存限制:65536KB
我们定义两种操作
操作1的格式 :I 字符串 S,加入 1 个字符串 S。
操作2的格式 :F 字符串S,查找字符串S是否在当前寻找前已经出现过
注释:同一个字符串可能多次被插入和查找,字符串长度\left|S\right|≤20,字符集为小写英文字母。
第一行,指令个数N。
接下来N行,每行一个指令。
对于每次查找,找到输出 ‘YES’,没找到输出 ‘NO’ 。
|
10 I abcdef I abcdef F abcdef F abcd I ef F fff F ef F abcdef I asd F assd |
对于 40\% 的数据 N≤5000
对于 100\% 的数据 N≤150000
这个也很简单,简直就是裸的hash(其实就是
hash不知道为什么一直打炸???,所以就直接上STL
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
#include <cstdio> #include <cstdlib> #include <cstring> #include <map> #include <iostream> std::map<std::string,char>hashT; int main() { int N;scanf("%d",&N); for(register int i=1;i<=N;i++) { char*c=(char*)malloc(sizeof(char));char s[21]; scanf("%s%s",c,s); std::string ss=s; if(c[0]=='I') hashT[ss]=1; else if(c[0]=='F') printf("%s\n",(hashT[ss]==1?"YES":"NO")); } return 0; } |
(注:STL太好用了,只不过多了个log,还被卡了常而已