#include<string.h>
#include<stdio.h>
#include<stdlib.h>
struct node{
char name[100];
char sex[10];
struct node *next;
};
int main()
{
struct node *head, *p, *q=NULL, *t,*t1;
char name[100], sex[10];
char x[] = "f", y[] = "m",temp[]="x";
int i,j=0;
head = NULL;
for (i = 0; i < 9; i++)
{
scanf("%s %s", name, sex);
p = (struct node*)malloc(sizeof(struct node*));
strcpy(p->name, name);
strcpy(p->sex, sex);
p->next = NULL;
if (head == NULL)
{
head = p;
}
else
{
q->next = p;
}
q = p;
}
t = head;
//下面是把链表的尾和头链接起来,不知道对不对
while (t != NULL)
{
if (t->next == NULL)
{
t->next = head;
break;
}
else
{
t = t->next;
}
}
t = head;
while (t != NULL)
//配对
{
j++;
if (strcmp(t->sex,x)==0)
//找到女的
{
if (strcmp(t->sex, y) == 0) //找到男的
{
printf("%s ", t->name);
//输出女的
strcpy(t->sex, temp);
//把性别改掉 避免下次出现重复
printf("%s\n", t->name);
//同上
strcpy(t->sex, temp);
}
}
else
{
t = t->next;
}
if (j == 9)
//结束掉
{
break;
}
}
}