日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Dictionary Aizu - ALDS1_4_C

發布時間:2024/5/6 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Dictionary Aizu - ALDS1_4_C 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。