标签:string 素数 row body 词典 memory 结束 void ane
附上代码:
#include <iostream> #include <cstdio> #include <cstring> using namespace std; typedef long long ll; char hash_z_g[100005][85]; char hash_z[100005][25]; bool vids_z_g[100005]; char hash_g_z[100005][25]; char hash_g[100005][85]; bool vids_g_z[100005]; int ct = 0; int judge(char ans) { if(ans == ‘\‘‘) return 27; if(ans == ‘ ‘) return 28; else return (ans - ‘a‘); } ll myhash(char str[]) { ll sum = 0; int len1 = strlen(str); for(int i = 0; i < len1; i ++) { sum = sum * 131 % 100003 + judge(str[i]); sum %= 100003; } return sum; } void insert_z_g(char str[], char strs[]) { ll num = myhash(str); if(!vids_z_g[num]) { vids_z_g[num] = true; strcpy(hash_z_g[num], strs); } else { while(vids_z_g[num]) {ct ++; num ++; num = num % 100003; } vids_z_g[num] = true; strcpy(hash_z_g[num], strs); } strcpy(hash_z[num], str); } void insert_g_z(char str[], char strs[]) { ll num = myhash(str); if(!vids_g_z[num]) { vids_g_z[num] = true; strcpy(hash_g_z[num], strs); } else { while(vids_g_z[num]) {ct ++; num ++; num = num % 100003; } vids_g_z[num] = true; strcpy(hash_g_z[num], strs); } strcpy(hash_g[num], str); } bool acfinds_z_g(char str[]) { ll num = myhash(str); if(vids_z_g[num]) { if(strcmp(str, hash_z[num]) == 0) { printf("%s\n", hash_z_g[num]); return true; } else { if(ct == 0) return false; int bj = 0; while(vids_z_g[num]) { num ++; bj ++; if(bj >= 100003) return false; num = num % 100003; if(strcmp(str, hash_z[num]) == 0) { printf("%s\n", hash_z_g[num]); return true; } } return false; } } else { return false; } } bool acfinds_g_z(char str[]) { ll num = myhash(str); if(vids_g_z[num]) { if(strcmp(str, hash_g[num]) == 0) { printf("%s\n", hash_g_z[num]); return true; } else { if(ct == 0) return false; int bj = 0; while(vids_g_z[num]) { num ++; bj ++; if(bj >= 100003) return false; num = num % 100003; if(strcmp(str, hash_g[num]) == 0) { printf("%s\n", hash_g_z[num]); return true; } } return false; } } else { return false; } } char str[205]; char sss[] = "@END@"; int main() { while(gets(str) != NULL) { if(strcmp(sss, str) == 0) { break; } else { char fl1[105], fl2[105]; int len = strlen(str); int f_1, f_2; f_1 = f_2 = 0; memset(fl1, 0, sizeof(fl1)); memset(fl2, 0, sizeof(fl2)); int flag = 1; for(int i = 0; i < len; i ++) { if(flag == 1) { if(str[i] == ‘[‘) { continue; } else if(str[i] == ‘]‘) { fl1[f_1] = ‘\0‘; flag ++; i ++; } else { fl1[f_1] = str[i]; f_1 ++; } } else if(flag == 2) { fl2[f_2] = str[i]; f_2 ++; } } fl2[f_2] = ‘\0‘; insert_z_g(fl1, fl2); insert_g_z(fl2, fl1); }} char temp[105]; int n; scanf("%d", &n); getchar(); for(int i = 0; i < n; i ++) { int flag = 0; cin.getline(temp, 105); int lens = strlen(temp); char re[105]; memset(re, 0, sizeof(re)); int f_re = 0; for(int i = 0; i < lens; i ++) { if(temp[i] == ‘[‘) { flag = 1; continue; } else if(temp[i] == ‘]‘) { continue; } else { re[f_re] = temp[i]; f_re ++; } } bool re_s; if(flag) re_s = acfinds_z_g(re); else re_s = acfinds_g_z(re); if(re_s == false) { printf("what?\n"); } } return 0; }
标签:string 素数 row body 词典 memory 结束 void ane
原文地址:https://www.cnblogs.com/qq136155330/p/10357430.html