哈工大答案

#include"stdio.h"
#include"stdlib.h"
#include"string.h"
#include<iostream>
using namespace std;
struct fri
{
    struct fri *f;
    struct fri *s;
    char num[20];
    char name[20];
};
int main()
{
    char op[80];
    int i,j;
    char name[20],num[20];
    struct fri *fr,*p,*ps,*pf,st,en;
    struct fri *ptf,stt,enn;
    st.name[0]='N';
    st.name[1]='o';
    st.name[2]='b';
    st.name[3]='o';
    st.name[4]='d';
    st.name[5]='y';
    st.name[6]='\0';
    st.f=&st;
    st.s=&en;
    en.f=&st;
    en.s=&en;
    stt.f=&stt;
    stt.s=&enn;
    enn.f=&stt;
    enn.s=&enn;
    do
    {
        gets(op);
        switch (op[0])
        {
        case 'I':
            i=7;
            fr=(struct fri*)malloc(sizeof(struct fri));
            while (op[i]!=' ')
            {
                fr->name[i-7]=op[i];
                i++;
            }
            fr->name[i-7]='\0';
            i++;
            j=i;
            while (op[i]!=' ')
            {
                num[i-j]=op[i];
                i++;
            }
            num[i-j]='\0';
            i+=8;
            j=i;
            while (op[i]!='\0')
            {
                name[i-j]=op[i];
                i++;
            }
            name[i-j]='\0';
            p=&st;
            while (p!=&en&&strcmp(p->name,fr->name)!=0)
                p=p->s;
            if (p!=&en)
            {
                strcpy(p->num,num);
                break;
            }
            p=&st;
            while (p!=&en&&strcmp(p->name,name)!=0)
                p=p->s;
            strcpy(fr->num,num);
            ps=p->s;
            ps->f=fr;
            p->s=fr;
            fr->f=p;
            fr->s=ps;
           // cout << 11111 << endl;
            break;
        case 'D':
            i=7;
            while (op[i]!='\0')
            {
                name[i-7]=op[i];
                i++;
            }
            name[i-7]='\0';
            p=&st;
            while (p!=&en&&strcmp(name,p->name)!=0)
                p=p->s;
            if (p==&en) break;
            pf=p->f;
            ps=p->s;
            ps->f=pf;
            pf->s=ps;
            free(p);
            break;
        case 'P':
            p=st.s;
            while (p!=&en)
            {
                pf=enn.f;
                ptf=(struct fri*)malloc(sizeof(struct fri));
                strcpy(ptf->name,p->name);
                strcpy(ptf->num,p->num);
                ptf->f=pf;
                ptf->s=&enn;
                pf->s=ptf;
                enn.f=ptf;
                p=p->s;
               // cout << enn.f << endl;
            }

            break;
        case 'E':
            p=st.s;
            while (p!=&en)
            {
                ps=p->s;
                free(p);
                p=ps;
            }
        }
    }
    while (op[0]!='E');
    p=stt.s;
    cout << p << endl;
    while (p!=&enn)
    {
        printf("%s %s\n",p->name,p->num);
        cout << 111111111111 << endl;
        ps=p->s;
        free(p);
        p=ps;
    }

    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值