统计非平凡子串数目

设S为一个长度为n的字符串,其中串的字符各不相同。写出具体程序,并计算出S中互异的非平凡子串(非空且不同于S本身)的个数

#include<stdio.h>
void main()
{
    int count=0,j,i,n;
    char *s="abcdef";
    n = strlen(s);
    int location;//子串开始位置
    for(i=1;i<n;i++)
    {
        location = 0;
        while(s[location+i-1]!='\0')
        {
            for(j=0;j<i;j++)
                printf("%c",s[location+j]);
            printf(" ");
            count++;//计数
            location++;//往后挪动一个位置
        }
        printf("\n");
    }
    printf("\nThe number of substrings is %d.\n",count);
}

猜你喜欢

转载自blog.csdn.net/weixin_42034217/article/details/84672573