69,371
社区成员
发帖
与我相关
我的任务
分享
#include<stdio.h>
#include<string.h>
#include<malloc.h>
int main()
{
int begin, end, step;
char str[] = "abcdefghijklmn";
int len = strlen(str);
char *substr = (char*)malloc(sizeof(str));
begin = 0;
end = len-1;
step = len-1;
while(1)
{
if (step == 0)
{
break;
}
memset(substr, 0, sizeof(str));
memcpy(substr, str+begin, step);
printf("%s\n", substr);
if (begin + step < end)
{
++begin;
continue;
}
if (begin + step == end)
{
begin = 0;
--step;
}
}
return 0;
}
#include <stdio.h>
#include <string.h>
char *a="abcde";
int L,i,j,k;
void main() {
L=strlen(a);
for (i=1;i<=L;i++) {
for (j=0;j<=L-i;j++) {
for (k=j;k<j+i;k++) {
printf("%c",a[k]);
}
printf("\n");
}
}
}
#include<stdio.h>
#include<string.h>
#include<malloc.h>
int main()
{
int begin, end, step;
char str[] = "abcdefghijklmn";
int len = strlen(str);
char *substr = (char*)malloc(sizeof(str));
begin = 0;
end = len-1;
step = len-1;
while(1)
{
if (step == 0)
{
break;
}
memset(substr, 0, sizeof(str));
memcpy(substr, str+begin, step);
/*找到满足条件退出*/
/*
if (strcmp(substr, "cdefg") == 0)
{
break;
}
*/
printf("%s\n", substr);
if (begin + step < end)
{
++begin;
continue;
}
if (begin + step == end)
{
begin = 0;
--step;
}
}
return 0;
}