//分数线划定(链表)
//6 3
//1000 90
//3239 88
//2390 95
//7231 84
//1005 95
//1001 88
//88 5
//1005 95
//2390 95
//1000 90
//1001 88
//3239 88
#include <stdio.h>
#include <stdlib.h>
typedef struct node
{
int bmh; //报名号
int score; //分数
struct node *next;
}Node;
void insertNode(Node *head, Node *s);
void output(Node *head, int m);
void destory(Node *head);
int main()
{
Node *head, *q;
head = (Node *)malloc(sizeof(Node));
head->next = NULL;
int group = 0, need = 0;
scanf("%d %d", &group, &need);
need = need * 1.5;
for(int i = 1; i <= group; i++)
{
q = (Node *)malloc(sizeof(Node));
scanf("%d %d", &q->bmh, &q->score);
insertNode(head, q);
}
output(head, need);
destory(head);
return 0;
}
//插入数据
void insertNode(Node *head, Node *s)
{
Node *p = head->next;
Node *prep = head;
while(p && (p->score > s->score || (p->score == s->score && p->bmh < s->bmh)))
{
prep = p;
p = p->next;
}
s->next = p;
prep->next = s;
}
//输出数据
void output(Node *head, int m)
{
Node *p = head->next;
int c = 0, ss;
while(p != NULL)
{
c++;
if(c == m)
{
ss = p->score;
p = p->next;
while(p->score == ss)
{
c++;
p = p->next;
}
break;
}
p = p->next;
}
printf("%d %d\n", ss, c);
p = head->next;
while(p && p->score >= ss)
{
printf("%d %d\n", p->bmh, p->score);
p = p->next;
}
}
//释放内存
void destory(Node *head)
{
Node *p = head, *q;
while(p)
{
q = p;
p = p->next;
free(q);
}
}
分数线划定(链表)-C语言
最新推荐文章于 2023-11-26 10:44:09 发布