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 |
生成代码In Reply To:雁过留声——字典树 Posted by:fanhqme at 2009-08-24 16:02:52 #include <cstdio> #include <string.h> #include <algorithm> #include <queue> using namespace std; char S[10][6]={ "SI", "STO", "PSI", "PSTO", "SPI", "SPTO", "SIP", "STPO", "STOP" }; char C[5][4][30]={ {"pron.","atr.n.","art.adj.n."}, {"pron.","atr.n.","art.adj.n."}, {"vi.","adv.vi.","v.","adv.v."}, {"vt.","adv.vt.","v.","adv.v."}, {"prep.atr.n.","prep.art.adj.n.","prep.pron."} }; FILE *fout=fopen("word.txt","w"); pair<int,int> stack[100]; int L; void DFS(int I,int a) { if(a>=strlen(S[I])) { for(int i=0;i<L;i++) fprintf(fout,"%s",C[stack[i].first][stack[i].second]); fprintf(fout,"\n"); return ;} if(S[I][a]=='S') { for(int i=0;i<3;i++) { stack[L++]=make_pair(0,i); DFS(I,a+1); L--; } } else if(S[I][a]=='O') { for(int i=0;i<3;i++) { stack[L++]=make_pair(1,i); DFS(I,a+1); L--;} } else if(S[I][a]=='I') { for(int i=0;i<4;i++){ stack[L++]=make_pair(2,i); DFS(I,a+1); L--;} } else if(S[I][a]=='T') { for(int i=0;i<4;i++){ stack[L++]=make_pair(3,i); DFS(I,a+1); L--;} } else if(S[I][a]=='P') { for(int i=0;i<3;i++){ stack[L++]=make_pair(4,i); DFS(I,a+1); L--;} } } int main() { for(int i=0;i<9;i++) DFS(i,0); getchar();getchar(); fclose(fout); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator