⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 作业题3.txt

📁 中南的数据结构试验1
💻 TXT
字号:

#define maxlen 250
#include<stdio.h>
#include<stdlib.h>
struct chuan{
int data;
char len[maxlen];
};
struct chuan creats(void)
{       struct chuan l;
	int i;
	for(i=0;i<maxlen;i++)
	{                                        /* 输入主串*/
		scanf("%c",&l.len[i]);
		if(l.len[i]=='\n')
		goto js;
	}
js:    printf("\n*********************\n");
	l.data=i;
	return l;
}
void disp(struct chuan l)
{
	int i;
	printf("\n+++++++++++++++++++\n");
	for(i=0;i<l.data;i++)
	printf("%c",l.len[i]);       /*在屏幕上显示主串*/
	printf("\n");
}
struct chuan replace (struct chuan l1,struct chuan l2,struct chuan l3)
{
	struct chuan l4;
	int i,j,k,m=0,n=0;
	k=l1.data;
	for(i=0;i<k;i++)
	{
		for(j=0;j<l2.data&&m==0;j++)
		{
		if(l1.len[i+j]!=l2.len[j])
		m=1;
		}
	if(m==0){
		for(j=0;j<l3.data;j++)
		{
		l4.len[n]=l3.len[j];
		n++;
		}
		i=i+l2.data-1;
		}
	else   {
		l4.len[n]=l1.len[i];
		n++;
		}
		m=0;
	}
	l4.data=n;
	return l4;
}
main()
{
	int i;
	struct chuan l1,l2,l3,l4;
	clrscr();
	printf("\n it is a replace string!\n");
	printf("***********************\n");
	printf("Enter the host string:\n");    /* 输入主串*/
	l1=creats();
	printf("\nEnter the replace string:\n");   /*输入要被替换的子串*/
	l2=creats();
	printf("\Enter the new string:\n");     /*输入替换的新子串*/
	l3=creats();
	printf("\n**********************\n");
	l4=replace(l1,l2,l3);
	printf("the old string:\n");
	disp(l1);
	printf("\nthe new string:\n");
	disp(l4);
	printf("\n press any key out!");
	getch();
	clrscr();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -