hdu 2142 (模拟,,,)

点击打开链接

/*




题目中的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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值