枚舉字符串的所有連續子串

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

int main(){
	char s[100],a[100];
	scanf("%s",s);
	int len=strlen(s);
	for(int i=0;i<len;i++){//從對應位置枚舉長度
		for(int j=1;j<=len-i;j++){
			memcpy(a,s+i,sizeof(char)*j);//從s+i的位置開始寫入長度爲j的字符 
			a[j]=0;
			printf("%s\n",a);		
		} 
	}
	
} 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章