武器排序HDU3293: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
 

    
 

    一道简略的结构体排序

    排序优先级

    1:按持有者名字

    2:按武器级别

    3:按武器名字

    水题

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

struct NODE
{
    char name[30];
    char lv[30];
    char ori[30];
} girl[505];

int cmp(NODE x,NODE y)
{
    if(strcmp(x.ori,y.ori))
        return strcmp(x.ori,y.ori)<0;
    if(strcmp(x.lv,y.lv))
    {
        if(!strcmp(x.lv,"wonderful"))
            return 1;
        if(!strcmp(y.lv,"wonderful"))
            return 0;
        if(!strcmp(y.lv,"so-so"))
            return 1;
        if(!strcmp(x.lv,"so-so"))
            return 0;
    }
    return strcmp(x.name,y.name)<0;
}

int main()
{
    int n,i,cas = 1;
    while(~scanf("%d",&n))
    {
        for(i = 0; i<n; i++)
            scanf("%s%s%s",girl[i].name,girl[i].ori,girl[i].lv);
        printf("Case %d\n",cas++);
        sort(girl,girl+n,cmp);
        char s[30];
        strcpy(s,girl[0].ori);
        int flag = 1;
        for(i = 0; i<n; i++)
        {
            if(flag)
            {
                printf("%s:\n",s);
                flag = 0;
            }
            printf("          %s %s\n",girl[i].name,girl[i].lv);
            if(strcmp(s,girl[i+1].ori))
            {
                strcpy(s,girl[i+1].ori);
                flag = 1;
            }
        }
    }

    return 0;
}

    
 

文章结束给大家分享下程序员的一些笑话语录: 自行车
一个程序员骑着一个很漂亮的自行车到了公司,另一个程序员看到了他,问 到,“你是从哪搞到的这么漂亮的车的?”
骑车的那个程序员说, “我刚从那边过来, 有一个漂亮的姑娘骑着这个车过来, 并停在我跟前,把衣服全脱了,然后对我说,‘你想要什么都可以’”。
另一个程序员马上说到, “你绝对做了一个正确的选择, 因为那姑娘的衣服你 并不一定穿得了”。

原文地址:https://www.cnblogs.com/xinyuyuanm/p/3093604.html