• HDU 3293 sort(结构体排序)


    Problem Description
    As is known to all, long long ago sailormoon once was an association of fighters. Till now, sailormoon is also an association of girls. Owe to some unknown reasons, girls are necessary to fight for peace.
    Their boss, lcy, wants to strengthen their ability, so he give them his precious collections---weapons for many years. Because these collections are really age-old, it is hard to recognize from one to another. So girls intend to sort them before they use. Each weapon has its name, origin and level of harmfulness ( level contains three ranks: wonderful, good, so-so).
    In order to make it clear, girls want to sort like this:
    firstly,sort according to the origin (sort by lexicographic order), if two or more have the same origin, they will be sorted together;
    secondly, sort according ranks, wonderful is the best, good is next, the third is so-so;
    thirdly, if two or more have same origin and rank, sort them according to the lexicographic order.
    
    
    
     
    
    Input
    Input contains multiply cases. Each case contains several lines. First line is an integer N(0<N<=500), representing the number of weapons. Then N lines follows. Each line represent a kind of weapon, and contains a set of strings representing name, origin and level of harmfulness. 
    Each string will not exceed 20 characters.
    Sure that same origin will not exist the same weapon.
     
    
    Output
    Please output your list after sorting (format according to sample, pay attention to the spaces,ten spaces need ^ ^).
     
    
    Sample Input
    5
    knife qizhou so-so
    gun qizhou wonderful
    knife zhengzhou good
    stick zhengzhou good
    rope shengzhou so-so
     
    
    Sample Output
    Case 1
    qizhou:
              gun wonderful
              knife so-so
    shengzhou:
              rope so-so
    zhengzhou:
              knife good
              stick good
    #include<stdio.h>
    #include<iostream>
    #include<cstring>
    #include<algorithm>
    #define N 10000
    using namespace std;
    struct SS{
        char place[200];
        char name[200];
        char rank[200];
        //string rank;
        int rankle;
        int num;
    }f[N];
    int cmp(SS a,SS b)
    {
        if(strcmp(a.place,b.place)!=0)
        return strcmp(a.place,b.place)<0;
        if(a.rankle!=b.rankle)
        return a.rankle>b.rankle;
        if(strcmp(a.name,b.name)!=0)
        return strcmp(a.name,b.name)<0;
        
    }
    int main()
    {   //freopen("1.txt","r",stdin);
        int test,i,n,m,flag,count=1;
        while(cin>>test)
        {
            for(i=0;i<test;i++)
            {
                cin>>f[i].name>>f[i].place>>f[i].rank;
                if(strcmp(f[i].rank,"wonderful")==0)
                f[i].rankle=3;
                //strcpy(f[i].rank,'3');这个地方也不能直接将3直接给rank也不能把‘3’给rank,所以用一个int型的rankle,
                if(strcmp(f[i].rank,"good")==0)
                f[i].rankle=2;
                //strcpy(f[i].rank,'2');直接对rankle进行比较
                if(strcmp(f[i].rank,"so-so")==0)
                f[i].rankle=1;
                //strcpy(f[i].rank,'1');
            }
            sort(f,f+test,cmp);
            flag=1;
            //count=1;
            cout<<"Case "<<count<<endl;
            char di[200];
            char names[200];
            strcpy(di,f[0].place);
            strcpy(names,f[0].name);
            for(i=0;i<test;i++)
            {
                if(strcmp(f[i].place,di)!=0)
                {
                    strcpy(di,f[i].place);
                    flag=1;
                    i--; 
                }
                if(strcmp(f[i].place,di)==0)
                {
                    if(flag==1)
                    {
                    cout<<f[i].place<<":"<<endl;
                    flag=0;
                    }
                    cout<<"          "<<f[i].name<<" "<<f[i].rank<<endl;
                    
                }
                
                
                
                
            } 
            count++;
            
        }
        return 0;
    }

  • 相关阅读:
    kioptrix-1
    4.4 CSRF
    upload-labs 练习笔记
    4.3 XSS
    外国人是怎样读编程书的呢?
    如何快速学习新语言
    Go开发环境配置
    Golang Package I
    MVC模式小结
    Flask基础知识
  • 原文地址:https://www.cnblogs.com/hezixiansheng8/p/3674743.html
Copyright © 2020-2023  润新知