| ||||||||||
Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
哪位大牛帮我看看我的代码为什么WA#include <iostream> using namespace std; struct trieNode { trieNode * next[26]; int id; bool word; trieNode() { int i; for(i=0;i<26;i++) next[i] = 0; id = 0; word = false; } }root; struct output { int i,j,d; }out[1010]; int dir[8][2] = {{-1,0},{-1,1},{0,1},{1,1},{1,0},{1,-1},{0,-1},{-1,-1}}; int l,c,w; char table[1010][1010],word[1010]; bool can(int ii,int jj) { return 0<= ii && ii<l &&0<= jj && jj<c; } void insert(int id) { trieNode * cur = &root; int index = 0; while(word[index] != '\0') { if(cur->next[word[index] - 'A'] == 0) cur->next[word[index] - 'A'] = new trieNode(); cur = cur->next[word[index] - 'A']; index++; } cur->word = true; cur->id = id; } void myfind(int ii, int jj, int kk) { int i = ii,j = jj; trieNode * cur = &root; while(true) { if(!can(i,j) || cur->next[table[i][j]-'A'] == 0) return; if(cur->next[table[i][j]-'A']->word == true && out[cur->next[table[i][j]-'A']->id].d == -1) { out[cur->next[table[i][j]-'A']->id].i = ii; out[cur->next[table[i][j]-'A']->id].j = jj; out[cur->next[table[i][j]-'A']->id].d = kk; return; } cur = cur->next[table[i][j] - 'A']; i += dir[kk][0]; j += dir[kk][1]; } } int main() { int i,j,k; while(scanf("%d %d %d",&l,&c,&w)!=EOF) { memset(out,-1,sizeof(out)); getchar(); for(i=0;i<l;i++) gets(table[i]); for(i=0;i<w;i++) { gets(word); insert(i+1); } for(i=0;i<l;i++) for(j=0;j<c;j++) for(k=0;k<8;k++) myfind(i,j,k); for(i=1;i<=w;i++) printf("%d %d %c\n",out[i].i,out[i].j,out[i].d+'A'); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator