|
5鱼币
为啥运行 不出来 哪里出问题啦 还请 朋友们 帮帮忙 看看 帮忙指正一下 谢谢啦
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct
- {
- char *ch;
- int length;
- }str;
- void getnext(str T,int *next)
- {
- int j = 0, i = 1;
- next[0] = 1;
- while(i<T.length)
- {
- if(j == 0 || T.ch[i] == T.ch[j])
- {
- next[i+1] = j+1;
- i++;
- j++;
-
- }
- else
- j = next[j];
- }
- }
- int main()
- {
- str s;
- char z[255] = "ababaaaba";
- s.length = 9;
- s.ch = (char *)malloc((s.length+1)*sizeof(char));
-
- for(int j=0;j<10;j++)
- s.ch[j]=z[j];
- //printf("%s \n",s.ch);
- int next[255];
- int i =1;
- getnext(s,next);
- free(s.ch);
-
- for(i;i<=s.length;i++)
- {
- printf("%d ",next[i]);
- }
- putchar('\n');
- return 0;
- }
复制代码 |
|