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;
    }

  • 相关阅读:
    双网卡主机无法管理的故障
    hosts文件导致无法访问网站
    获取webshell的十种方法
    XSS跨站攻击
    Ubuntu 使用中的问题总结
    ubuntu linux 13.04更新
    mysql root密码重置
    防火墙工作模式简介
    SE 2014年4月30日
    SE 2014年4月29日
  • 原文地址:https://www.cnblogs.com/Both-wings/p/3749632.html
Copyright © 2011-2022 走看看