以前写的数据结构课设

用c/c++实现的数据结构课设,写的比较低端,那个模糊查找的应该用LCS写的,我那个时候写的不好,现在也没什么兴趣改了,现在贴出来,作为一个纪念,勿喷~~~


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<conio.h>
#include <process.h>
using namespace std;

#define N 40

typedef struct Node{
  char  a[N][N];   //姓名 性别 生日 电话 所在地 分组
  char  name[N]; //名字首字母
  struct Node *next;

} *node;

char Group[N][N];   //  1      2     3     4      5        6
char type[N][N]={"","姓名","性别","生日","电话","所在地","分组"};


int vis[N];
char start[N][N];
char to[N][N],k;
int pos[3]={1};

node root,tail;

void readFriend();   //读取 Friend.txt 文件夹中 联系人的内容
void readGroup();    //读入Group.txt 文件夹中 分组信息
void idshow();       //显示各种操作的信息
void typeshow();     //显示操作哪一个属性的函数
void change();       //修改联系人信息的函数
void inset();        //新添联系人
void delet() ;       //删除联系人的操作(可以删除多个具有相同属性的联系人)
void showall();      //输出所有联系人
void show();         //输出特定属性的联系人

bool In(wchar_t start, wchar_t end, wchar_t code);   //返回汉字首字母的函数
char convert(wchar_t n) ;
char* TransformToSpell(char name[]) ;

bool Strcmp(char *a,char *b)     //自定义的Strcmp 函数,从头开始,当目标串是文本串字串就返回true
{
    for(int i=0;b[i];i++)
        if(a[i]!=b[i]) return false;
    return true;

}


void readFriend()    //读取 Friend.txt 文件夹中 联系人的内容
{
	int i,j;
	char ch[N];

	root=(node)malloc(sizeof(Node));
	root->next=NULL;

	root->next=NULL;
	tail=root;

	while(~scanf("%s",ch))
	{
		node temp;

		temp=(node)malloc(sizeof(Node));

		strcpy(temp->a[1],ch);

		for(int i=2;i<=6;i++)
		{
			scanf("%s",temp->a[i]);
		}

        i=6;
        if((*(temp->a[6]))>='0'&&(*(temp->a[6]))<='9')
         strcpy(temp->a[i],Group[*(temp->a[6])-'0']);

          for(int i=0;i<1;i++)
          if(*(temp->a[pos[i]])<0)
           {
             char hh[N];
             strcpy(hh,TransformToSpell(temp->a[pos[i]]));

             strcpy(temp->name,hh);
           }

        temp->next=tail->next;
        tail->next=temp;
        tail=temp;
	}
}

void readGroup()     //读入Group.txt 文件夹中 分组信息
{
	int i;
	char ch[N];

	while(~scanf("%d%s",&i,ch))
	{
		strcpy(Group[i],ch);
	}
}


void idshow()        //显示各种操作的信息
{
	printf("\n       欢迎使用联系人管理系统,联系人信息已经读入,请选择您的操作\n\n");
	printf("\t\t - - - - - - - - - - - - - - - - \n\n") ;
	printf("\t\t|     修改联系人信息请按   1    |\n\n");
	printf("\t\t|     添加新的联系人请按   2    |\n\n");
	printf("\t\t|     删除已有联系人请按   3    |\n\n");
	printf("\t\t|     查看所有联系人请按   4    |\n\n");
	printf("\t\t|     查看特征联系人请按   5    |\n\n") ;
    printf("\t\t|     结束所有的操作请按   0    |\n\n");
    printf("\t\t - - - - - - - - - - - - - - - -\n") ;
    printf("\n请输入操作对应的序号:  ");
}

void typeshow()      //显示操作哪一个属性的函数
{
    printf("\n");

    for(int i=1;i<=6;i++)
	{
		printf("%-7s ",type[i]);
	}

	printf("\n");

	for(int i=1;i<=6;i++)
		printf("%-7d ",i);
	printf("\n\n");

}

void change()       //修改联系人信息的函数
{
	typeshow();
	k=0;

	printf("请输入欲修改的上面的选项对应的编号 内容 和修改后的内容(有多项一直输入,0为结束): \n");

    int x;
    while(scanf("%d",&x),x)
	{
		vis[k]=x;
		scanf("%s",start[k]);
		scanf("%s",to[k]);
		k++;
	}

	node temp=root->next;

    int time=0;

	while(temp)
	{
	   bool flag=true;
	   for(int i=0;i<k;i++)
			if(strcmp(temp->a[vis[i]],start[i]))
	      {
	   	      flag=false;
	   	      break;
	      }

	   if(flag)
		 {
		 	for(int i=0;i<k;i++)
			  strcpy(temp->a[vis[i]],to[i]);
			time++;
		 }
		temp=temp->next;
	}
    if(time==0)
	{
		printf("Sorry,联系人中无此人 !\n");
		return ;
	}
	printf("修改人数为  %d \n\n",time);
}


void inset()        //新添联系人
{
	printf("请输入 姓名 性别 生日 电话 所在地 分组  \n      ");
    node temp;
	temp=(node)malloc(sizeof(Node));

	for(int i=1;i<=6;i++)
	  scanf("%s",temp->a[i]);

    char ss=*(temp->a[6]);

    if(ss>='1'&&ss<='9')
       strcpy(temp->a[6],Group[ss-'0']);


       for(int i=0;i<1;i++)
          if(*(temp->a[pos[i]])<0)
           {
             strcpy(temp->name,TransformToSpell(temp->a[pos[i]]));
            // printf("%s\n",temp->name);
           }

    temp->next=root->next;
	root->next=temp;

	printf("插入成功!\n\n");
}


void delet()       //删除联系人的操作(可以删除多个具有相同属性的联系人)
{
	typeshow();
	k=0;

	printf("请输入欲删除的上面的选项对应的编号 内容 和修改后的内容(有多项一直输入,0为结束): \n");

	int x;

	while(scanf("%d",&x),x)
	{
		vis[k]=x;
		scanf("%s",start[k]);
		k++;
	}

	node s,e;

	int time=0;

	s=root;
	e=s->next;
	while(e)
	{
	   bool flag=true;
	   for(int i=0;i<k;i++)
			if(strcmp(e->a[vis[i]],start[i]))
	      {
	   	      flag=false;
	   	      break;
	      }

	   if(flag)
	   {
	   	time++;
	   	  s->next=e->next;
	   	  e=e->next;
	   }
	   else
	   {
	   	  s=e;
	   	  e=e->next;
	   }
	}

    if(time==0)
	{
		printf("Sorry,联系人中无此人 !\n");
		return ;
	}

	printf("此次操作删除了 %d 个元素 !\n\n",time);
}


void showall()     //输出所有联系人
{
	node temp=root->next;
	while(temp)
	{
		printf("\n");
		for(int i=1;i<=6;i++)
			printf("%-10s ",temp->a[i]);

		printf("\n");
		temp=temp->next;
	}
	printf("\n\n");

}

void show()        //输出特定属性的联系人
{

	typeshow();
	k=0;

	printf("请输入欲查看的上面的选项对应的编号 内容(有多项一直输入,0为结束): \n");

    int x;
    while(scanf("%d",&x),x)
	{
		vis[k]=x;
		scanf("%s",start[k]);
		if(x==6&&start[k][0]>='0'&&start[k][0]<='9')
			strcpy(start[k],Group[start[k][0]-'0']);

		k++;
	}
    printf("\n");

	node temp=root->next;
    int num=0;

	while(temp)
	{
           bool flag=true;

           for(int i=0;i<k;i++)
          {

               if(vis[i]==1&&start[i][0]>0)
               {

                    if(!Strcmp(temp->name,start[i]))
                        flag=false;
                    continue;
               }

               if(!Strcmp(temp->a[vis[i]],start[i]))
                {
                      flag=false;
                      break;
                }

          }

           if(flag)
             {

               num++;
               printf("\n");
               for(int i=1;i<=6;i++)
                    printf("%-10s ",temp->a[i]);

                 printf("\n");
             }

          temp=temp->next;

      }

   if(num==0)
	printf("Sorry,没有符合条件的联系人!\n");
   printf("\n");

}

bool In(wchar_t start, wchar_t end, wchar_t code)
{
	if (code >= start && code <= end)
	{
		return true;
	}
	return false;
}

char convert(wchar_t n)
{
	if (In(0xB0A1,0xB0C4,n)) return 'a';
	if (In(0XB0C5,0XB2C0,n)) return 'b';
	if (In(0xB2C1,0xB4ED,n)) return 'c';
	if (In(0xB4EE,0xB6E9,n)) return 'd';
	if (In(0xB6EA,0xB7A1,n)) return 'e';
	if (In(0xB7A2,0xB8c0,n)) return 'f';
	if (In(0xB8C1,0xB9FD,n)) return 'g';
	if (In(0xB9FE,0xBBF6,n)) return 'h';
	if (In(0xBBF7,0xBFA5,n)) return 'j';
	if (In(0xBFA6,0xC0AB,n)) return 'k';
	if (In(0xC0AC,0xC2E7,n)) return 'l';
	if (In(0xC2E8,0xC4C2,n)) return 'm';
	if (In(0xC4C3,0xC5B5,n)) return 'n';
	if (In(0xC5B6,0xC5BD,n)) return 'o';
	if (In(0xC5BE,0xC6D9,n)) return 'p';
	if (In(0xC6DA,0xC8BA,n)) return 'q';
	if (In(0xC8BB,0xC8F5,n)) return 'r';
	if (In(0xC8F6,0xCBF0,n)) return 's';
	if (In(0xCBFA,0xCDD9,n)) return 't';
	if (In(0xCDDA,0xCEF3,n)) return 'w';
	if (In(0xCEF4,0xD188,n)) return 'x';
	if (In(0xD1B9,0xD4D0,n)) return 'y';
	if (In(0xD4D1,0xD7F9,n)) return 'z';
	return '\0';
}

char* TransformToSpell(char name[]){

	char chr[N];
	wchar_t wchr = 0;

	char* Spell = new char[strlen(name)/2];
	memset(Spell, 0x00, sizeof(char)*strlen(name)/2+1);

	for (unsigned int i = 0, j = 0; i < (strlen(name)/2); ++i)
	{
		memset(chr, 0x00, sizeof(chr));
		chr[0] = name[j++];
		chr[1] = name[j++];
		chr[2] = '\0';

		wchr = 0;
		wchr = (chr[0] & 0xff) << 8;
		wchr |= (chr[1] & 0xff);

		Spell[i] = convert(wchr);
	}
	return Spell;
}


int main()
{
    freopen("H:/c++/数据结构实验/寒假作业/Group.txt","r",stdin);

    //freopen("H:/c++/数据结构实验/寒假作业/out.txt","w",stdout);

    readGroup();

    freopen("H:/c++/数据结构实验/寒假作业/Friend.txt","r",stdin);

    readFriend();

    //freopen("H:/c++/数据结构实验/寒假作业/op.txt","r",stdin);

    freopen("CON","r",stdin);

    int op;
    char ch[N];

    while(1)
	{
         bool flag=false;

		 idshow();

	     scanf("%d",&op);

		 if(!op) break;  //结束操作

		 if(op==1)    //修改
		 {
		 	change();
		 	flag=true;
		 }

		 if(op==2)    //插入
		 {
		 	inset();
		 	flag=true;
		 }

         if(op==3)   //删除
		 {
		 	delet();
		 	flag=true;
		 }

		 if(op==4)  //输出内容
		 {
		 	showall();
		 	flag=true;
		 }

         if(op==5)
		 {
		 	show();
		 	flag=true;
		 }

         if(!flag)
	      printf("Sorry,输入有误!\n\n");

		printf("请输入任意键返回主页面 :  ");


		getchar();
		getchar();

		system("cls");
	}

    fclose(stdin);

	freopen("H:/c++/数据结构实验/寒假作业/Friend.txt","w",stdout);
	showall();

	return 0;
}





Friend.txt


柯亚妮     女         1994       18834662020 湖北       朋友       

李勇       男         1991       18912345678 湖北武汉   大学同学   

刘晨       女         1992       15301391234 北京       高中同学   

王敏       女         1980       13838197777 河南郑州   朋友       

张立       男         1985       15612346598 呼和浩特   高中同学   

小四川     男         1894       18088888888 武汉       订餐       


Group.txt


1     大学同学	
2     高中同学		
3     家人		
4     朋友		
5     老师		
6     订餐	


in.txt
李勇    男    1991        18912345678    湖北武汉   1
刘晨    女    1992        15301391234    北京       2
王敏    女    1980        13838197777    河南郑州   3
张立    男    1985        15612346598    呼和浩特   2
小四川  男    1894        18088888888    武汉       6  


op.txt


4

2
ksh  男 1994  18749328896 武汉 2

4

1
2 ksh hello
0

4

3
2 hello
0

4

5
3 男
0

5
7 高中同学
0

0




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值