#include<stdio.h>
#include<string.h>
#define M 4000000
#define NIL (-1)
#define L 14
char H[M][L]; /* Hash Table */
int getChar(char ch){
if ( ch == 'A') return 1;
else if ( ch == 'C') return 2;
else if ( ch == 'G') return 3;
else if ( ch == 'T') return 4;
}
/* convert a string into an integer value */
long long getKey(char str[]){
long long sum = 0, p = 1, i;
for ( i
= 0; i
< strlen(str
); i
++ ){ sum += p*(getChar(str[i]));
p *= 5;
}
return sum;
}
int h1(int key){ return 0x7fffFFFF & ((key << 16) | (key >> 16)); }
int h2(int key){ return 0x7fffFFFF ^ key; }
int find(char str[]){
/* your task */
long long key = getKey(str);
int h;
h = (int)(0x7fffFFFFLL & (key >> 32)) % M;
if (strcmp(H
[h
], str
) == 0) return 1; h = (int)(0x7fffFFFFLL & key) % M;
if (strcmp(H
[h
], str
) == 0) return 1; h = h1((int)(0x7fffFFFFLL & (key >> 32))) % M;
if (strcmp(H
[h
], str
) == 0) return 1; h = h2((int)(0x7fffFFFFLL & (key >> 32))) % M;
if (strcmp(H
[h
], str
) == 0) return 1; h = h1((int)(0x7fffFFFFLL & key)) % M;
if (strcmp(H
[h
], str
) == 0) return 1; h = h2((int)(0x7fffFFFFLL & key)) % M;
while (H[h][0] != '\0') {
return 1;
}
++h;
if (h == M) {
h = 0;
}
}
return 0;
}
int insert(char str[]){
/* your task */
long long key = getKey(str);
int h;
h = (int)(0x7fffFFFFLL & (key >> 32)) % M;
if (H[h][0] == '\0') {
return h;
}
h = (int)(0x7fffFFFFLL & key) % M;
if (H[h][0] == '\0') {
return h;
}
h = h1((int)(0x7fffFFFFLL & (key >> 32))) % M;
if (H[h][0] == '\0') {
return h;
}
h = h2((int)(0x7fffFFFFLL & (key >> 32))) % M;
if (H[h][0] == '\0') {
return h;
}
h = h1((int)(0x7fffFFFFLL & key)) % M;
if (H[h][0] == '\0') {
return h;
}
h = h2((int)(0x7fffFFFFLL & key)) % M;
while (H[h][0] != '\0') {
++h;
if (h == M) {
h = 0;
}
}
return h;
}
int main(){
int i, n, h;
char str[L], com[9];
for ( i = 0; i < M; i++ ) H[i][0] = '\0';
for ( i = 0; i < n; i++ ){
scanf("%s %s", com
, str
);
if ( com[0] == 'i' ){
insert(str);
} else {
if (find(str)){
} else {
}
}
}
return 0;
}
I2luY2x1ZGU8c3RkaW8uaD4KI2luY2x1ZGU8c3RyaW5nLmg+CgojZGVmaW5lIE0gNDAwMDAwMAojZGVmaW5lIE5JTCAoLTEpCiNkZWZpbmUgTCAxNAoKY2hhciBIW01dW0xdOyAvKiBIYXNoIFRhYmxlICovCgppbnQgZ2V0Q2hhcihjaGFyIGNoKXsKICBpZiAoIGNoID09ICdBJykgcmV0dXJuIDE7CiAgZWxzZSBpZiAoIGNoID09ICdDJykgcmV0dXJuIDI7CiAgZWxzZSBpZiAoIGNoID09ICdHJykgcmV0dXJuIDM7CiAgZWxzZSBpZiAoIGNoID09ICdUJykgcmV0dXJuIDQ7Cn0KCi8qIGNvbnZlcnQgYSBzdHJpbmcgaW50byBhbiBpbnRlZ2VyIHZhbHVlICovCmxvbmcgbG9uZyBnZXRLZXkoY2hhciBzdHJbXSl7CiAgbG9uZyBsb25nIHN1bSA9IDAsIHAgPSAxLCBpOwogIGZvciAoIGkgPSAwOyBpIDwgc3RybGVuKHN0cik7IGkrKyApewogICAgc3VtICs9IHAqKGdldENoYXIoc3RyW2ldKSk7CiAgICBwICo9IDU7CiAgfQogIHJldHVybiBzdW07Cn0KCmludCBoMShpbnQga2V5KXsgcmV0dXJuIDB4N2ZmZkZGRkYgJiAoKGtleSA8PCAxNikgfCAoa2V5ID4+IDE2KSk7IH0KaW50IGgyKGludCBrZXkpeyByZXR1cm4gMHg3ZmZmRkZGRiBeIGtleTsgfQoKaW50IGZpbmQoY2hhciBzdHJbXSl7CgogICAgLyogeW91ciB0YXNrICovCiAgICBsb25nIGxvbmcga2V5ID0gZ2V0S2V5KHN0cik7CiAgICBpbnQgaDsKICAgIGggPSAoaW50KSgweDdmZmZGRkZGTEwgJiAoa2V5ID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KTsKCQl9IGVsc2UgewoJCSAgICBpZiAoZmluZChzdHIpKXsKCQkJCXByaW50ZigieWVzXG4iKTsKCQkgICAgfSBlbHNlIHsKCQkJCXByaW50Zigibm9cbiIpOwoJCSAgICB9CgkJfQogICAgfQoKICAgIHJldHVybiAwOwp9Cg==
MTMKaW5zZXJ0IEFBQQppbnNlcnQgQUFDCmluc2VydCBBR0EKaW5zZXJ0IEFHRwppbnNlcnQgVFRUCmZpbmQgQUFBCmZpbmQgQ0NDCmZpbmQgQ0NDCmluc2VydCBDQ0MKZmluZCBDQ0MKaW5zZXJ0IFQKZmluZCBUVFQKZmluZCBU
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