//主函数:
#include "kk.h"
int main()
{
ap num;
printf("请你输入一连串字符:\n");
scanf("%s",num.st);
bzero(num.location,sizeof(num.location));//清空位置标记位
bzero(num.st2,sizeof(num.st2)); //清空窗口串标志位
num.move=0; //窗口移动标量
printf("\n");
printf("请你输入子串\n");
scanf("%s",num.st1);
sort(num.st1);//对子串排序
printf("%s\n",num.st1); //检查子串是否排序
search(&num);
myprintf(&num);
/* sequence(&num,strlen(num.st1));
printf("%s\n",num.st2); */
/* for(int i=0;i<strlen(num.st);i++)
{
sequence(&num,strlen(num.st1));
num.ly++;
if(!strcmp(num.st1,num.st2))
{
printf("你好\n");
}
} */
}
//头文件
#ifndef _KK_H
#define _KK_H
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef int uint_32;
typedef struct
{
char st[100];//主串
char st1[100]; //子窜
char st2[100]; //窗串
int location[100];
int move;
}ap;
void search(ap *num); //查找
void myprintf(ap *num); //打印
void sequence(ap *num,int n); //窗口获取
void sort(char *num); //冒泡排序
#endif
//函数.c文件
#include "kk.h"
void search(ap *num) //查找记录函数
{
//printf("%s\n",num->st);
//printf("%s\n",num->st1);
//printf("%ld\n",strlen(num->st1));
char *p=num->st;
uint_32 u=0;
while(*p!='\0') // abcdaadsfsf
{ // bc
sequence(num,strlen(num->st1));
num->move++;
if(strcmp(num->st1,num->st2)==0)
{
printf("你输入%s\n",num->st2);
printf("你输入%d\n",num->move);
num->location[u]=num->move-1;
num->location[u+1]=num->move+strlen(num->st1)-2;
u+=2;
}
p++;
}
}
void myprintf(ap *num)//打印函数
{
uint_32 start=0;
uint_32 end=0;
uint_32 length=0;
for(int i=0;i<100;i++)
{
if(num->location[i]!=0)
{
length++;
}
}
printf("%d的lwngth:\n",length++);
printf("%s的异位词子串:\n",num->st);
for(int j=0;j<length;j++)
{
start=num->location[j];
end=num->location[++j];
printf("%d--%d:",start,end);
for(start;start<=end;start++)
{
printf("%c",num->st[start]);
}
printf("\n");
}
}
void sequence(ap *num,int n)
{
bzero(num->st2,sizeof(num->st2));
if((num->move+strlen(num->st1))!=strlen(num->st)+1)
{
strncpy(num->st2,num->st+num->move,n);
sort(num->st2);
}
}
void sort(char *num)
{
char swap='0';
for(int j=0;j<strlen(num);j++)
{
for(int i=0;i<strlen(num)-j-1;i++)
{
if(num[i]>num[i+1])
{
swap=num[i];
num[i]=num[i+1];
num[i+1]=swap;
}
}
}
}