Search III

Your task is to write a program of a simple dictionary which implements the following instructions:

insert str: insert a string str in to the dictionary
find str: if the distionary contains str, then print ‘yes’, otherwise print ‘no’

Input

In the first line n, the number of instructions is given. In the following n lines, n instructions are given in the above mentioned format.

Output

Print yes or no for each find instruction in a line.

Constraints

A string consists of ‘A’, ‘C’, ‘G’, or ‘T’
1 ≤ length of a string ≤ 12
n ≤ 1000000

Sample Input 1

5
insert A
insert T
insert C
find G
find A

Sample Output 1

no
yes

Sample Input 2

13
insert AAA
insert AAC
insert AGA
insert AGG
insert TTT
find AAA
find CCC
find CCC
insert CCC
find CCC
insert T
find TTT
find T

Sample Output 2

yes
no
no
yes
yes
yes

code

/*^....0^ .1 ^1^..     011.^     1.0^ 1  ^    ^0.11 ^        ^..^0.           ^ 0^.0            1 .^.1             ^0 .........001^.1               1. .111100....01^00             ^   11^        ^1. .1^1.^                              ^0  0^.^                                 ^0..1.1                                   1..^1 .0                                     ^  ^00.                                     ^^0.^^ 0                                     ^^110.^0   0 ^                                     ^^^10.01^^     10  1 1                                      ^^^1110.101     10  1.1                                      ^^^1111110010    01  ^^                                        ^^^1111^1.^           ^^^10  10^ 0^ 1                                            ^^111^^^0.1^       1....^11     0                                               ^^11^^^ 0..  ....1^   ^ ^1.     0^                                               ^11^^^ ^ 1 111^     ^ 0.10   00 11                                               ^^^^^   1 0           1.0^  ^0  ^0                                                ^^^^    0            0.0^  1.0  .^                                               ^^^^    1 1          .0^.^  ^^  0^                             ^1                ^^^^     0.         ^.11 ^      11                             1.                ^^^     ^ ^        ..^^..^      ^1                             ^.^               ^^^       .0       ^.00..^      ^0                              01               ^^^       ..      0..^1 ..        .1                             ^.^              ^^^       1 ^  ^0001^  1.        00                              0.             ^^^        ^.0 ^.1. 0^.        ^.^                             ^.^            ^^^         ..0.01 .^^.         .^                  1001        ^^            ^^^         . 1^. ^ ^.         11                0.    1         ^           ^^          0.0  ^.          0              ^0       1                   ^^^          0.0.^  1.          0^             0       .1                   ^^^          ...1   1.          00            .        .1                  ^^^           ..1      1.         ^.           0         .^                  ^^            ..0.     1.          .^          .         0                                  ..1     1.          01          .        .                                 ^ 0^.^     00          ^0          1.       ^                                 1 1.0      00           .            ^^^^^^                                   ..^      00           01                                                    ..1.       00           10                                                   1 ^^.1       00           ^.                                            ^^^    .1..        00            .1                                        1..01    ..1.1         00           1.                                       ..^      10^ 1^         00           ^.1                                      0 1      1.1           00            00                                       ^  1   ^.           00            ^.^                                        10^  ^^1.1           00             00                                              10^..^           1.             ^.                                               1.0 1            ^.              00                 00                            .^^            ^.              ^ 1                00   ^0000^     ^               011 0             ^.               00.0^              ^00000   1.00.1              11. 1              0               1^^0.01                      ^^^                01.^              ^                1   1^^                                       ^.^1 1                                                                              0...                                                                              1 ^1                                                                               1^ ^                                                                             .01                                                                             ^ 1..                                                          1.1            ^0.0^ 0                                                           1..01^^100000..0^1 1                                                            ^ 1 ^^1111^ ^^0 ^                                                             ^ 1      1000^.1                                                               ^.^     .   00..                                                                1.1    0.   01.                                                                  .    1.   .^1.                                                                 1    1.   ^0^ .                                                                 ^.1 00    01^.0                                                                  001.     .^*/
// Virtual_Judge —— Dictionary Aizu - ALDS1_4_C.cpp created by VB_KoKing on 2019-05-02:11.
/* Procedural objectives:Variables required by the program:Procedural thinking:Functions required by the program:*/
/* My dear Max said:
"I like you,
So the first bunch of sunshine I saw in the morning is you,
The first gentle breeze that passed through my ear is you,
The first star I see is also you.
The world I see is all your shadow."FIGHTING FOR OUR FUTURE!!!
*/
#include <iostream>
#include <cstring>
#include <cstdio>#define M 1046527
#define NIL -1
#define L 14using namespace std;char H[M][L];//将字符转换为数值
int get_char(char ch) {switch (ch) {case 'A':return 1;case 'C':return 2;case 'G':return 3;case 'T':return 4;default:return 0;}
}//将字符串转换为数值并生成key
long long get_key(char str[]) {long long sum = 0, p = 1;for (int i = 0; i < strlen(str); i++) {sum += p * (get_char(str[i]));p *= 5;}return sum;
}int h1(int key) { return key % M; }int h2(int key) { return 1 + (key % (M - 1)); }int find(char str[]) {long long key = get_key(str), h;for (int i = 0; ; i++) {h = (h1(key) + i * h2(key)) % M;if (strcmp(H[h], str) == 0) return 1;else if (strlen(H[h]) == 0) return 0;}
}int insert(char str[]) {long long key = get_key(str), h;for (int i = 0; ; i++) {h = (h1(key) + i * h2(key)) % M;if (strcmp(H[h], str) == 0) return 1;else if (strlen(H[h]) == 0) {strcpy(H[h], str);return 0;}}
}int main() {int n;scanf("%d",&n);char str[L], com[9];for (int i = 0; i < M; i++) H[i][0] = '\0';for (int i = 0; i < n; i++) {scanf("%s %s",com,str);if (com[0] == 'i') insert(str);else {if (find(str)) printf("yes\n");else printf("no\n");}}return 0;
}

Dictionary Aizu - ALDS1_4_C相关推荐

  1. vim 高级应用 原文地址 http://www.2maomao.com/blog/wp-content/uploads/vim_tips.txt

    最佳vim技巧 ---------------------------------------- # 信息来源 ---------------------------------------- www ...

  2. Python 字典(Dictionary) get()方法

    Python 字典(Dictionary) get()方法 描述 Python 字典(Dictionary) get() 函数返回指定键的值,如果值不在字典中返回默认值. 语法 get()方法语法: ...

  3. Python 字典(Dictionary)

    Python 字典(Dictionary) 字典是另一种可变容器模型,且可存储任意类型对象. 字典的每个键值(key=>value)对用冒号(:)分割,每个对之间用逗号(,)分割,整个字典包括在 ...

  4. BFS:图的最短路径  Aizu - 0558 ​​​​​​​Cheese

    Cheese Aizu - 0558 大意:在H * W的地图上有N个奶酪工厂,每个工厂分别生产硬度为1-N的奶酪.有一只老鼠准备从出发点吃遍每一个工厂的奶酪.老鼠有一个体力值,初始时为1,每吃一个工 ...

  5. Aizu - 0033 Ball

    这题书上写让用DFS--可是这一比较就出来啊-- Ball Aizu - 0033 図のように二股に分かれている容器があります.1 から 10 までの番号が付けられた10 個の玉を容器の開口部 A か ...

  6. Dictionary作为数据源绑定,调用c++库中返回为BYTE*的函数,listView项排序

    最近在做一个电子档案管理的项目.现在还处于初期,只是做一个简单demo拿去跟客户演示.至于最后谈不谈得下来,到底做不做,反正我是不看好,但没因为这样就马马虎虎.草草了事.这个项目算是b/s加c/s混合 ...

  7. 技术图文:浅析 C# Dictionary实现原理

    背景 对于 C# 中的 Dictionary类 相信大家都不陌生,这是一个 Collection(集合) 类型,可以通过 Key/Value (键值对) 的形式来存放数据:该类最大的优点就是它查找元素 ...

  8. python报错 ValueError: dictionary update sequence element #0 has length 1; 2 is require

    原文链接地址: https://blog.csdn.net/weixin_40894428/article/details/80683137 字符串转字典要用eval(),这个方法很多书上都没有介绍, ...

  9. 迭代var()内置函数的时候出现RuntimeError: dictionary changed size during iteration的解决办法...

    下午看了Mr Seven的教学视频,其中有一段讲全局变量的视频,迭代输出全局变量的时候报错了. 视频中的做法: for k,v in vars().items():print(k) 打印结果 for ...

最新文章

  1. ant table表格整行点击事件并获取当前行的数据
  2. python获取数据库查询的元数据_Python数据库、MySQL存储引擎、使用分区表、更改表结构、获取数据库元数据...
  3. java基础-可执行jar包
  4. [RDLC]报表根据字段列动态加载图片(二)
  5. 对称密码的编程使用(DES、3DES、AES)
  6. JavaFX 2 GameTutorial第5部分
  7. mysql json 创建索引_MySQL · 最佳实践 · 如何索引JSON字段
  8. android 动态获取全县_省市县 ------ 三级滚动(android)
  9. 项目投标注意点001---项目投标那点事
  10. 大型网站限流算法的实现和改造
  11. 博通:NFC将成手机标配nbsp;新芯…
  12. 大数据元数据管理系统功能有哪些
  13. 卷积神经网络第三周作业 Autonomous driving application - Car detection - v1
  14. Java加密的几种方式
  15. 元数据是什么?举例告诉你什么是元数据
  16. 数据库入门_查询语句
  17. Elastic Search Java API(文档操作API、Query DSL查询API)、es搜索引擎实战demo
  18. 名帖292 张瑞图 行书《论书卷》
  19. 老程序员教你如何提高开发效率、成为大神1——人文思维进化与信众
  20. 快速搭建一个小型博客网站

热门文章

  1. 我们越来越浮躁的心靠什么去滋润
  2. 整型数据在内存中的存放形式
  3. 6_2 铁轨(UVa514)栈
  4. 我弥留之际 - 许立志 (珍藏)
  5. wpf控件提示Value ‘’ can not convert
  6. 2009年全国计算机软件考试推荐用书目录
  7. php fopen 图片下载,php curl与fopen下载远程服务器图片实例
  8. mysql经常问到的面试题_20道BAT面试官最喜欢问的JVM+MySQL面试题(含答案解析)...
  9. python建立虚拟环境不成功_virtualenv 创建虚拟环境不成功
  10. 驱动备份工具哪个好_原神元素反应工具人推荐一览 元素反应工具人哪个好