/SDUT 2057 金牌 银牌 铜牌
记录这个题之前先发表一下感受,这个题的整体思路不难,但实现起来不是很容易,至少对我来说。输出排名的函数一开始没写出代码来,受同学的启发,写出来,提交成功了,特意记录一下。
做完这个题之后,我发现在链表中排序可以作为一个模板,这个功能做题时用到不少。收藏这个模板,在以后
做题时会省很多时间。
以下是源码:/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Node
{
char Name[22];
int score;
struct Node *next;
};
void show (struct Node *x);//显示
struct Node *Creat(int n); //创建
struct Node *Add(struct Node *shead,struct Node *x);//增加
struct Node *Delete(struct Node * x,char str[]);//删除
struct Node *Change(struct Node *x,char str[],int score);//改变
void FindKing(struct Node *x);//找排名
struct Node *Sort(struct Node *x);//排序
int main ()
{
struct Node *head,*p;
int n,score;
char ch,str[22];
scanf ("%d",&n);
head=Creat(n);
while ((scanf (" %c",&ch))!=EOF)
{
if (ch==‘A’)
{
p=(struct Node *)malloc (sizeof (struct Node));
if (p= =NULL)
exit (0);
p->next=NULL;
scanf ("%s%d",p->Name ,&p->score );
head=Add(head,p);
}