图书管理

题目链接:图书管理

我真的太弱了,这种XX题做了五六遍

对于这道题,建一个Hash就行

直接上代码:

 1 #include<cstdio>
 2 #include<string>
 3 #include<cstring>
 4 #include<iostream>
 5 #include<algorithm>
 6 using namespace std;
 7 const int N = 1e8+7, Prime =  17;//Prime最好取一个素数,N不要太大,也不能太小,1e8正好,memset速度快而且减小了冲突
 8 int T;
 9 bool vis[N];
10 char s[205];
11 int main()
12 {
13     scanf("%d",&T);
14     while(T--)
15     {
16         scanf("%s",s);
17         if(strcmp(s,"add")==0)
18         {
19             int hs=0;
20             gets(s);
21             int len=strlen(s);
22             for(int i=0;i<len;++i)
23                 hs=(hs*Prime+s[i])%N;
24             vis[hs]=true;
25         }else{
26             int hs=0;
27             gets(s);
28             int len=strlen(s);
29             for(int i=0;i<len;++i)
30                 hs=(hs*Prime+s[i])%N;
31             if(vis[hs]) printf("yes\n");
32             else  printf("no\n");
33         }
34     }
35     return 0;
36 }
View Code

一个1e8害的我搞了半个晚上emmm……

转载于:https://www.cnblogs.com/cptbtptpbcptbtptp/p/11397310.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值