#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;
}
哈工大答案
最新推荐文章于 2023-08-01 21:13:09 发布