zoukankan      html  css  js  c++  java
  • ZOJ2727

    一道水题  数据小 用效率最低的冒泡都能过
    我这是用的c++的sort
    注意有个坑的地方:You should output a blank line between two test cases.  也就是最后一组样例输出没有空行
    #include<stdio.h>
    #include<string.h>
    #include<algorithm>
    #include<iostream>
    using namespace std;
    struct stu
    {
        char name[100];
        int year;
        int price;
    } s[110];
    int  cmn(stu a,stu b)
    {
        if(strcmp(a.name,b.name)!=0)
            return strcmp(a.name,b.name)<0;
        if(a.year!=b.year)
            return a.year<b.year;
        return a.price<b.price;
    }
    int cmp(stu a,stu b)
    {
        if(a.price!=b.price)
            return a.price<b.price;
        if(strcmp(a.name,b.name)!=0)
            return strcmp(a.name,b.name)<0?1:0;
        return a.year<b.year;
    }
    int cmy(stu a,stu b)
    {
        if(a.year!=b.year)
            return a.year<b.year;
        if(strcmp(a.name,b.name)!=0)
            return strcmp(a.name,b.name)<0?1:0;
        return a.price<b.price;
    }
    int main()
    {
        int n,i;
        char t[10];
        scanf("%d",&n);
        while(1)
        {
            if(n==0) break;
            for(i=0; i<n; i++)
                scanf("%s %d %d",s[i].name,&s[i].year,&s[i].price);
            scanf("%s",t);
            if(strcmp(t,"Name")==0)
                sort(s,s+n,cmn);
            else if(strcmp(t,"Price")==0)
                sort(s,s+n,cmp);
            else
                sort(s,s+n,cmy);
            for(i=0; i<n; i++)
                printf("%s %d %d ",s[i].name,s[i].year,s[i].price);
            scanf("%d",&n);
            if(n!=0) printf(" ");
        }
        return 0;
    }

  • 相关阅读:
    记2008年7月25日午后 心情
    [多媒体]词典编码
    [多媒体]算术编码、游程编码
    [多媒体]数据压缩的类型
    [多媒体]理解PCM、DPCM、APCM、ADPCM
    C++异常处理
    [转]linux上SVN解决冲突的办法
    从海量数据查找有或者没有出现的数据
    八数码问题
    [转]linux中强大的screen命令
  • 原文地址:https://www.cnblogs.com/Both-wings/p/3749632.html
Copyright © 2011-2022 走看看