|  | 
 
 发表于 2020-6-13 10:43:59
|
显示全部楼层 
| 复制代码#include<stdio.h>
#include<stdlib.h>
typedef struct user{
        char name[5];
        int point;
        struct user *next;
}User;
//建立用户结构体链表 
void CreateUserList(User *L)
{
        char c;
        int i, count=0;
        User *p, *pre;
        pre = L;
        while((c = getchar()) != '\n')
        {
                if(c >= 'a' && c <= 'z')
                {
                        p = (User *)malloc(sizeof(User));
                        p->name[0] = c;
                        count = 1;
                        while((c = getchar()) != ':')
                        {
                                p->name[count] = c;
                                count++;
                        }
                        for(i=count; i<5; i++)
                        {
                                p->name[i] = '#';
                        }
                        scanf("%d", &p->point);
                        pre->next = p;
                        p->next = NULL;
                        pre = p;
                }
        }
}
void PrintUserList(User *L)
{
        User *p;
        int i;
        p = L->next;
        while(p != NULL)
        {
                for(i=0; i<5; i++)
                {
                        if(p->name[i] != '#')
                                printf("%c", p->name[i]);
                }
                printf(":%d ", p->point);
                p = p->next;
        }
}
//查找结构体链表里对应point为输入值的那个结点 
void FindLuck(User *L)
{
        User *p;
        int target, i;
        p = L->next;
        scanf("%d", &target);
        while(p->point != target)
                p = p->next;
        for(i=0; i<5; i++)
        {
                if(p->name[i] != '#')
                        printf("%c", p->name[i]);
        }
}
int main()
{
        User L;
        CreateUserList(&L);
        //PrintUserList(&L);用于测试建立链表 
        FindLuck(&L);
        return 0;
}
 | 
 |