搜索
查看: 1309|回复: 0
打印 上一主题 下一主题

[啊哈!算法] 结构体快排

[复制链接]
跳转到指定楼层
楼主
发表于 2013-2-20 20:23:20 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
[code=Cpp width=740px]#include <stdio.h>

struct note
{
        int num;
    char name[21];
    char aut[21];
}a[51];

int cmp(const void *x,const void *y)
{
        if( (*((struct note *)x)).num > (*((struct note *)y)).num)
                return 1;
    else
                return 0;
}

int main()
{
        int n;
    int i;
    freopen("111.in","r",stdin);
    freopen("111.out","w",stdout);
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
                scanf("%d",&a.num);
        getchar();
        gets(a.name);
        gets(a.aut);
    }
    qsort(&a[1],n,sizeof(a[0]),cmp);

    for(i=1;i<=n;i++)
    {
                printf("%d\n%s\n%s\n",a.num,a.name,a.aut);
    }

        sleep(3000);
        return 0;
}[/code]
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

广播台
特别关注
快速回复 返回顶部 返回列表