上文提到
http://blog.csdn.net/zhanghaiyang9999/article/details/41864169
能否顺序打印单词。
顺序打印单词代码如下:
char *dict[]={"a","is","book","boo","this"}; bool isword(char* wd) { for(int i=0;i<sizeof(dict)/sizeof(dict[0]);i++) { if(strcmp(dict[i],wd) == 0) return true; } return false; } bool splitter2(const char* src) { char word[100]={0}; char tempsrc[100]={0}; int i=0; int nlen = strlen(src); if(nlen == 0) return true; for(i=nlen - 1;i >=0;i--) { strncpy(word,src + i,nlen - i); if(isword(word)) { memset(tempsrc,0,sizeof(tempsrc)); strncpy(tempsrc,src,i); if(splitter2(tempsrc)) { printf("word=%s\n",word); return true; } } } if(i < 0) return false; return true; }
时间: 2024-11-10 19:02:23