$$ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Self-defined math definitions %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Math symbol commands \newcommand{\intd}{\,{\rm d}} % Symbol 'd' used in integration, such as 'dx' \newcommand{\diff}{{\rm d}} % Symbol 'd' used in differentiation ... $$

C语言:连续子串

题目

输入一个字符串,输出其所有的子串(不包含本身,输出每个子串间有空格)。

子串:对于一个字符串变量,例如"adereegfbw",它的子串就是像"ader"这样可以从中找到的连续的字符串。

 例如:
  输入:abcde
  输出:a b c d e ab bc cd de abc bcd cde abcd bcde


代码


#include<stdio.h>

  int main(){
    int i,j,k,step;
    char a[100];
	
    scanf("%s",&a);
    for(i=0;a[i]!='\0';i++){
      printf("%c ",a[i]);
    }
    for(step=2;step<i;step++){
      for(j=0;j<i-step+1;j++){
        for(k=j;k<j+step;k++){
          printf("%c",a[k]);
        }
	printf(" ");
      }
    }
  return 0;
  } 
posted @ 2022-11-18 11:50  Shin404  阅读(122)  评论(0)    收藏  举报