能过样例,但是交上去RE求助 本蒟蒻的代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
using namespace std;
short tre[100001][60];
char fanyi[100001][60];
short val[1000001];
bool endstr[201];
char fy[100];//翻译后的
char yl[100];//原来的
int cnt = 1;
void insert(string str, int xb) {
int len = str.length(), pos = 1;
for (int i = 0; i < len; i++) {
int ch = str[i] - 'a';
if (!tre[pos][ch]) {
tre[pos][ch] = ++cnt;
}
pos = tre[pos][ch];
}
val[pos] = xb;
endstr[pos] = true;
}
int search(string str) {
int len = str.length(), pos = 1;
for (int i = 0; i < len; i++)
{
int ch = str[i] - 'a';
pos = tre[pos][ch];
if (!pos)
return false;
}
if (endstr[pos]) {
return val[pos];
}
return 0;
}
string tmp;
char ttmp[60];
int main() {
int i = 0;
char ch;
while (scanf("%s%c", fanyi[++i], &ch)!=EOF)
{
if(ch=='\n')break;
scanf("%s",yl);
insert(yl, i);
}
char cx[11];
strcpy(cx,fanyi[i]);
int ok = search(cx);
if (!ok)
printf("eh\n");
else
printf("%s\n", fanyi[ok]);
while(scanf("%s", cx)!=EOF)
{
int ok = search(cx);
if (!ok)
printf("eh\n");
else
printf("%s\n", fanyi[ok]);
}
return 0;
}