#include #include #include using namespace std; const int KIND = 26; const int MAXN = 1000000; int cnt_node; int R,C; char map[505][505]; char word[10005][22]; struct node{ bool isword; int r,c; node* next[KIND]; void init(){ r=c=-1; isword=false; memset(next, 0, sizeof(next)); } }Heap[MAXN]; inline node* new_node(){ Heap[cnt_node].init(); return &Heap[cnt_node++]; } void insert(node* root, char *str){ for(char *p=str; *p; ++p){ int ch=*p-'A'; if(root->next[ch]==NULL) root->next[ch] = new_node(); root=root->next[ch]; } root->isword=true; } void search(node* root, char *str, int row, int col){ for(char *p=str; *p; ++p){ int ch=*p-'A'; if(root->next[ch]==NULL) return ; root=root->next[ch]; if(root->isword && root->r==-1 && root->c==-1){ root->r=row, root->c=col; } } if(root->isword && root->r==-1 && root->c==-1){ root->r=row, root->c=col; } } void output(node* root, char *str){ for(char *p=str; *p; ++p){ int ch=*p-'A'; if(root->next[ch]==NULL) return; root=root->next[ch]; } if(root->isword) printf("%d %d\n", root->r, root->c); } int main(){ cnt_node=0; node* root=new_node(); scanf("%d%d%*c",&R,&C); for(int i=0; i