通讯录

/*****************************************************
     File name:tong_xun_lu.c


    Author: dtt


   Date:2018-01-12 20:16
*****************************************************/


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>


#define FALSE 0;
#define TRUE  1;


typedef int ElemType;
typedef int Status;




typedef struct st
{
    char num[20];
    char name[30];
    char telephone[20];
    char address[50];
    char email[30];
    struct st *next;
}Contacts;


void Pos(int x, int y);
Status init(Contacts **head);    //初始化
Status Add_tail(Contacts *head);      //新建联系人
void Output (Contacts *head);    //输出到屏幕
Status Read_file(Contacts *head);    //读文件
void Search(Contacts *head);    //查找
Status Delete(Contacts *head);    //删除
Status update(Contacts *head);    //修改联系人信息
void Output_file(Contacts *head);    //输出到文件
void clear(Contacts **head);    //清空
void Insert_Sort(Contacts *head);  //根据学号排序




int main()
{
    struct tm *t;
    time_t tt;
    time(&tt);
    t = localtime(&tt);    //为了打印出系统当前时间,百度的方法


    Contacts *head;
    init(&head);
    Read_file(head);
    int choose;


    while(1)
    {
        printf("\n\n\n\n");
        printf("                *********************************************\n");
        printf("                *                    主菜单                 *\n");
        printf("                * 输入数字执行操作:                        *\n");
        printf("                *      1:查看联系人        4.更改联系人信息 *\n");
        printf("                *      2:新建联系人        5.删除联系人     *\n");
        printf("                *      3:查找联系人        0:退出           *\n");
        printf("                *                                           *\n");
        printf("                *     操作时间:%4d年%02d月%2d日%02d:%02d:%02d      *\n",
                                                t->tm_year+1900,t->tm_mon+1,t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec);
        printf("                *********************************************\n");
        printf("\n\n");
        scanf("%d",&choose);


        switch(choose)
        {
            case 1:
                    Insert_Sort(head);
                    Output(head);
                    //Output_file(head);
                    break;
            case 2:
                    Add_tail(head);
                    Output_file(head);
                    break;
            case 3:
                    Search(head);
                    break;
            case 4:
                    update(head);
                    Output_file(head);
                    break;
            case 5:
                    Delete(head);
                    Output_file(head);
                    break;
            case 0:
                    clear(&head);
                    break;
            default:
                    printf("输入错误,重新输入!\n");
                    break;
        }


        if (choose == 0)
        {
            break;
        }
        getchar();
    }


    return 0;
}




Status init(Contacts **head)
{
    Contacts *newContacts = (Contacts *) malloc (sizeof(Contacts));
    if (newContacts == NULL)
    {
        return FALSE;
    }


    newContacts->next = NULL;
    *head = newContacts;


    return TRUE;
}


Status Read_file(Contacts *head)
{
    int flag;
    Contacts *newContacts,*p;
    FILE *fp;
    p = head;
    fp = fopen("/mnt/hgfs/share/tong_xun_lu_a.txt","r");


    fscanf(fp,"%d",&flag);
    while(flag != 0)
    {
        p = head;
        newContacts = (Contacts *) malloc (sizeof(Contacts));
        if (newContacts == NULL)
        {
            return FALSE;
        }


        while(p->next)
        {
            p=p->next;
        }


        newContacts->next = NULL;
        p->next = newContacts;


        fscanf(fp,"%s%s%s%s%s",newContacts->num,newContacts->name,newContacts->telephone,
                                newContacts->address,newContacts->email);
        fscanf(fp,"%d",&flag);
    }


    fclose(fp);
    return TRUE;
}


Status Add_tail(Contacts *head)
{
    Contacts *p;
    Contacts *newContacts = (Contacts *) malloc (sizeof(Contacts));
    if (newContacts == NULL)
    {
        return FALSE;
    }


    p = head;


    while(p->next)
    {
        p = p->next;
    }


    printf("\n\n请输入新建联系人的学号,姓名,电话号码,地址,email:\n\n\n\n");
    scanf("%s%s%s%s%s",newContacts->num,newContacts->name,newContacts->telephone,newContacts->address,newContacts->email);


    newContacts->next = p->next;
    p->next = newContacts;


    printf("添加联系人成功!\n");


    return TRUE;
}


void Search(Contacts *head)
{
    int choose,flag = 0;
    Contacts *q = head;
    char array[50];


    while(1)
    {
        printf("                **********************************************\n");
        printf("                *   请选择查找方式:                         *\n");
        printf("                *      1:根据姓名查找       2:根据号码查找   *\n");
        printf("                *      0:返回上一级菜单                      *\n");  
        printf("                **********************************************\n");


        scanf("%d",&choose);


        switch(choose)
        {
            case 1:
                    flag = 0;
                    printf("请输入要查找联系人的姓名:\n\t\t\t");
                    scanf("%s",array);
                    while(q->next)
                    {
                        if (strcmp(q->next->name,array) == 0)
                        {
                            flag = 1;
                            printf("找到该联系人:\n\n");
                            printf("    学号:%s\t 姓名:%s\t 号码:%s\t 地址:%s\t Email:%s\n\n\n",q->next->num,
                            q->next->name,q->next->telephone,q->next->address,q->next->email);
                        }
                        q = q->next;
                    }
                    if(flag == 0)
                    {
                        printf("    查无此人!\n");
                    }


                    q = head;
                    break;


            case 2:
                    flag = 0;
                    printf("请输入要查找联系人的地址:\n\t\t\t");
                    scanf("%s",array);
                    while(q->next)
                    {
                        if (strcmp(q->next->address,array) == 0)
                        {
                            flag = 1;
                            printf("找到该联系人:\n\n");
                            printf("    学号:%s\t 姓名:%s\t 号码:%s\t 地址:%s\t Email:%s\n\n\n",q->next->num,
                            q->next->name,q->next->telephone,q->next->address,q->next->email);
                        }
                        q = q->next;
                    }
                    if(flag == 0)
                    {
                        printf("    查无此人!\n");
                    }


                    q = head;
                    break;


            case 0:
                    break;
            default:
                    printf("输入错误,重新输入!\n");
                    break;


        }


        if (choose == 0)
        {
            break;
        }
        getchar();
   }


}


void Output (Contacts *head)
{
    int i = 0;
    if (head->next == NULL)
    {
        printf("无联系人信息!\n");
    }
    else
    {
        printf("\n\n\n\n\n\n\n");
        printf("    联系人信息:\n\n");
        while(head->next)
        {
            printf("             学号:%s\t 姓名:%s\t 号码:%s\t 地址:%s\t Email:%s\n"
                ,head->next->num,head->next->name,head->next->telephone,head->next->address,head->next->email);
            head = head->next;
            i++;
        }
        printf("\n\n\n");
    }
}


Status update(Contacts *head)
{
    int flag = 0;
    Contacts *q = head;
    Contacts *p = (Contacts *) malloc (sizeof(Contacts));
    if (p == NULL)
    {
        return FALSE;
    }


    printf("请输入要修改联系人的姓名:  ");
    scanf("%s",p->name);
    while(q->next)
    {
        if (strcmp(q->next->name,p->name) == 0)
        {
            flag = 1;
            printf("输入要修改的信息:\n\t\t");
            scanf("%s%s%s%s%s",q->next->num,q->next->name,q->next->telephone,q->next->address,q->next->email);
            printf("    修改成功!\n");
        }
        q = q->next;
    }


    if (flag == 0)
    {
        printf("    查无此人!\n");


        return FALSE;
    }


    free(p);
    return TRUE;
}


void Output_file(Contacts *head)
{
    FILE *fp;
    int k = 1;
    fp = fopen("/mnt/hgfs/share/tong_xun_lu_a.txt","w+");
    while(head->next)
    {
        fprintf(fp, "%d ",k++);   //输出的时候在每个联系人前面输个序号
        fprintf(fp,"%s     %s     %s      %s      %s\r\n"
                ,head->next->num,head->next->name,head->next->telephone,head->next->address,head->next->email);
        head = head->next;
    }


    fprintf(fp, "%d\n",0);


    fclose(fp);
}


Status Delete(Contacts *head)
{
    int flag = 0;
    Contacts *p = head;
    //Contacts *temp;
    char name[50];
    printf("请输入要删除联系人的姓名:\n\t\t\t");
    scanf("%s",name);
    while(p->next)
    {
        if (strcmp(p->next->name,name) == 0)
        {
            flag++;
        }
        p = p->next;
    }
    if (flag == 0)
    {
        printf("    查无此人!\n");
    }
    if (flag == 1)
    {
        p = head;
        while(p->next)
        {
            if (strcmp(p->next->name,name) == 0)
            {
                Contacts *temp = p->next;
                p->next = temp->next;
                free(temp);
                printf("删除成功!\n");
            }
            else
            {
                p = p->next;
            }
        }
    }


    return TRUE;
}


void clear(Contacts **head)
{
    Contacts *temp;
    while((*head)->next)
    {
        temp = (*head)->next;
        (*head)->next = (*head)->next->next;
        free(temp);
    }


    free(*head);
}


void Insert_Sort(Contacts *head)
{
    Contacts *p;
    if (head->next->next == NULL || head->next == NULL)
    {
        return;
    }
    Contacts *head2 = head->next->next;
    Contacts *q;  


    head->next->next = NULL;


    while(head2)
    {
        p = head;
        q = head2;
        head2 = head2->next;


        while(p->next)
        {
            if (strcmp(q->num,p->next->num) > 0)
            {
                p = p->next;
            }
            else
                break;
        }


        q->next = p->next;
        p->next = q;
    }
}
基于遗传算法的新的异构分布式系统任务调度算法研究(Matlab代码实现)内容概要:本文档围绕基于遗传算法的异构分布式系统任务调度算法展开研究,重点介绍了一种结合遗传算法的新颖优化方法,并通过Matlab代码实现验证其在复杂调度问题中的有效性。文中还涵盖了多种智能优化算法在生产调度、经济调度、车间调度、无人机路径规划、微电网优化等领域的应用案例,展示了从理论建模到仿真实现的完整流程。此外,文档系统梳理了智能优化、机器学习、路径规划、电力系统管理等多个科研方向的技术体系与实际应用场景,强调“借力”工具与创新思维在科研中的重要性。; 适合人群:具备一定Matlab编程基础,从事智能优化、自动化、电力系统、控制工程等相关领域研究的研究生及科研人员,尤其适合正在开展调度优化、路径规划或算法改进类课题的研究者; 使用场景及目标:①学习遗传算法及其他智能优化算法(如粒子群、蜣螂优化、NSGA等)在任务调度中的设计与实现;②掌握Matlab/Simulink在科研仿真中的综合应用;③获取多领域(如微电网、无人机、车间调度)的算法复现与创新思路; 阅读建议:建议按目录顺序系统浏览,重点关注算法原理与代码实现的对应关系,结合提供的网盘资源下载完整代码进行调试与复现,同时注重从已有案例中提炼可迁移的科研方法与创新路径。
【微电网】【创新点】基于非支配排序的蜣螂优化算法NSDBO求解微电网多目标优化调度研究(Matlab代码实现)内容概要:本文提出了一种基于非支配排序的蜣螂优化算法(NSDBO),用于求解微电网多目标优化调度问题。该方法结合非支配排序机制,提升了传统蜣螂优化算法在处理多目标问题时的收敛性和分布性,有效解决了微电网调度中经济成本、碳排放、能源利用率等多个相互冲突目标的优化难题。研究构建了包含风、光、储能等多种分布式能源的微电网模型,并通过Matlab代码实现算法仿真,验证了NSDBO在寻找帕累托最优解集方面的优越性能,相较于其他多目标优化算法表现出更强的搜索能力和稳定性。; 适合人群:具备一定电力系统或优化算法基础,从事新能源、微电网、智能优化等相关领域研究的研究生、科研人员及工程技术人员。; 使用场景及目标:①应用于微电网能量管理系统的多目标优化调度设计;②作为新型智能优化算法的研究与改进基础,用于解决复杂的多目标工程优化问题;③帮助理解非支配排序机制在进化算法中的集成方法及其在实际系统中的仿真实现。; 阅读建议:建议读者结合Matlab代码深入理解算法实现细节,重点关注非支配排序、拥挤度计算和蜣螂行为模拟的结合方式,并可通过替换目标函数或系统参数进行扩展实验,以掌握算法的适应性与调参技巧。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值