/*
题目中的number把我给坑了,这个number课翻译为两个意思:个数和标号。。自己当做标号的。。。
还有没注意到字典序那个单词。。
you should first print the maximal score and thenumber that whose score is the maximum, then print all of their namesLexi cographicly(字典序)
其他都好说。。。
2013/04/21-21:06
*/
#include"stdio.h"
#include"string.h"
#include"stdlib.h"
struct node
{
int score;
char name[10];
int mark;
}A[1011];
int cnt=0;
int cmp(const void *a,const void*b)
{
if((*(struct node*)a).score==(*(struct node*)b).score)
return strcmp((*(struct node*)a).name,(*(struct node*)b).name);
else
return (*(struct node*)a).score-(*(struct node*)b).score;
}
void new_fun(char *s,int x)
{
int i;
for(i=0;i<cnt;i++)
{
if(strcmp(A[i].name,s)==0&&A[i].mark==1)break;
}
if(i!=cnt)
{
A[i].score=x;
printf("update succeed\n");
}
else
{
strcpy(A[cnt].name,s);
A[cnt].score=x;
A[cnt].mark=1;
cnt++;
printf("A new record\n");
}
}
void ave_fun()
{
int i,t;
double max;
max=0;t=0;
for(i=0;i<cnt;i++)
{
if(A[i].mark==1)
{
t++;
max+=A[i].score;
}
}
if(t==0)printf("0.00\n");
else printf("%.2f\n",max*1.0/t);
}
void max_fun()
{
int i,t;
int max,j;
max=0;t=0;
j=0;
for(i=0;i<cnt;i++)
{
if(A[i].mark==1)
{
t++;
if(A[i].score>max)
{
max=A[i].score;
j=i;
}
}
}
if(t==0)printf("0 0\n");
else
{
t=0;
for(i=0;i<cnt;i++)
{
if(A[i].mark==1&&A[i].score==max)
t++;
}
printf("%d %d\n",max,t);
qsort(A,cnt,sizeof(A[0]),cmp);
for(i=0;i<cnt;i++)
{
if(A[i].mark==1&&A[i].score==max)
printf("%s\n",A[i].name);
}
}
}
void del_fun(char *s)
{
int i;
for(i=0;i<cnt;i++)
{
if(A[i].mark==1)
{
if(strcmp(A[i].name,s)==0)
{
A[i].mark=0;break;
}
}
}
if(i==cnt)printf("no such record\n");
else printf("delete succeed\n");
}
int main()
{
int a;
char s1[10],s2[10];
memset(A,0,sizeof(A));
while(1)
{
scanf("%s",s1);
if(strcmp(s1,"NEW")==0)
{
scanf("%s%d",s2,&a);
new_fun(s2,a);
}
else if(strcmp(s1,"MAX")==0)max_fun();
else if(strcmp(s1,"AVERAGE")==0)ave_fun();
else if(strcmp(s1,"DELETE")==0)
{
scanf("%s",s2);
del_fun(s2);
}
else if(strcmp(s1,"QUIT")==0){break;}
}
return 0;
}