Description

In his memoir So, Anyway. . ., comedian John Cleese writes of the class di erence between his father(who was "middle-middle-middle-lower-middle class") and his mother (who was  "upper-upper-lower-middle class"). These fine distinctions between classes tend to confuse American readers, so you are to write a program to sort a group of people by their classes to show the true distinctions.

There are three main classes: upper, middle, and lower. Obviously, upper class is the highest,and lower class is the lowest. But there can be distinctions within a class, so upper-upper is ahigher class than middle-upper, which is higher than lower-upper. However, all of the upper classes(upper-upper, middle-upper, and lower-upper) are higher than any of the middle classes.

Within a class like middle-upper, there can be further distinctions as well, leading to classes like lower-middle-upper-middle-upper. When comparing classes, once you've reached the lowest level of detail, you should assume that all further classes are the equivalent to the middle level of  the previous level of detail. So upper class and middle-upper class are equivalent, as are middle-middle-lower-middle and lower-middle.

Input

The rst line of input containsn(1<=n<=1 000), the number of names to follow. Each of the followingnlines contains the name of a person (a sequence of 1 or more lowercase letters `a'-`z'),a colon, a space, and then the class of the person. The class of the person will include one or more modifiers and then the word class. The colon, modi ers, and the wordclasswill be separatedfrom each other by single spaces. All modifiers are one of upper,middle, or lower. It is guaranteed that the input is well-formed. Additionally, no two people have the same name. Input lines are no longer than 256 characters.

Output

Print the n names, each on a single line, from highest to lowest class. If two people have equivalent classes, they should be listed in alphabetical order by name.

Sample

//Sample Input

mom: upper upper lower middle class
dad: middle middle lower middle class
queenelizabeth: upper upper class
chair: lower lower class
unclebob: middle lower middle class rich: lower upper class
mona: upper upper class
dave: middle lower class
charles: middle class
tom: middle class
william: lower middle class
carl: lower class
violet: middle class
frank: lower class
mary: upper class //Sample Output
queenelizabeth
mom
dad
unclebob
chair mona
mary
rich
charles
tom
violet
william
carl
dave
frank

题意:

已知班级有上中下之分,班级里又有上中下之分,以此类推。现在给出多个人以及他们所在的班级,要求按照从上到下的顺序给他们排序。

给定的所在班级的顺序为从后到前排列,例如 upper lower class是低于lower  upper  class(先比较class之前的,以此往前推)。

如果没有排列,默认为中等,例如upper class是高于lower  upper  class(upper class相当于middle upper  class)。

如果两个班级相等,按照姓名的字典序排序。

思路:

简单起见,可以将upper标记为3,middle标记为2,lower标记为1,数组初始化为2,方便用strcmp排序。

从前往后便利数组的时候,最后要将得到的标记的数组翻转一下。

代码:

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<iostream>
struct node
{
char name[];
char lever[];
char le[];
} z[]; using namespace std; bool cmp(struct node a,struct node b)
{
if(strcmp(a.le,b.le)==)//如果标记的数组相等
return strcmp(a.name,b.name)<;//按照姓名排序
else
return (strcmp(a.le,b.le)>);//否则按照标记的排序
} void Reverse(char *s,int n)//字符串翻转
{
for(int i=,j=n-; i<j; i++,j--)
{
char c=s[i];
s[i]=s[j];
s[j]=c;
}
} int main()
{
int n ;
int logo=;
int flag=;
while(~scanf("%d",&n))
{
for(int i=; i<n; i++)
{
logo=;
flag=;
scanf("%s",z[i].name);
int str = strlen(z[i].name);
z[i].name[str-] = ;//去掉冒号
for(int j=; j<; j++)
{
if(j==)
z[i].le[j]=;
else
z[i].le[j]='';
}
while()
{
flag++;
scanf("%s",z[i].lever);
if(strcmp("upper",z[i].lever)==)
z[i].le[logo++]='';
if(strcmp("middle",z[i].lever)==)
z[i].le[logo++]='';
if(strcmp("lower",z[i].lever)==)
z[i].le[logo++]='';
if(strcmp("class",z[i].lever)==)
break;
}
Reverse(z[i].le,flag-);
} sort(z,z+n,cmp); for(int i=; i<n; i++)
{
printf("%s",z[i].name);
printf("\n");
}
}
}

Classy(排序)的更多相关文章

  1. UVaLive 7370 Classy (排序,比较)

    题意:给定 n 个人,和他们的数进行比较,从后面开始比,如果不够长,加middle接着比,直到没有,如果还相同比名字. 析:很水的题,就不用说了. 代码如下: #pragma comment(link ...

  2. Codeforces 1036C Classy Numbers 【DFS】

    <题目链接> 题目大意: 对于那些各个位数上的非0数小于等于3的数,我们称为 classy number ,现在给你一个闭区间 [L,R]  (1≤L≤R≤1018).,问你这个区间内有多 ...

  3. CF1036C Classy Numbers dfs+二分

    Classy Numbers time limit per test 3 seconds memory limit per test 256 megabytes input standard inpu ...

  4. javascript中的Array对象 —— 数组的合并、转换、迭代、排序、堆栈

    Array 是javascript中经常用到的数据类型.javascript 的数组其他语言中数组的最大的区别是其每个数组项都可以保存任何类型的数据.本文主要讨论javascript中数组的声明.转换 ...

  5. iOS可视化动态绘制八种排序过程

    前面几篇博客都是关于排序的,在之前陆陆续续发布的博客中,我们先后介绍了冒泡排序.选择排序.插入排序.希尔排序.堆排序.归并排序以及快速排序.俗话说的好,做事儿要善始善终,本篇博客就算是对之前那几篇博客 ...

  6. JavaScript实现常用的排序算法

    ▓▓▓▓▓▓ 大致介绍 由于最近要考试复习,所以学习js的时间少了 -_-||,考试完还会继续的努力学习,这次用原生的JavaScript实现以前学习的常用的排序算法,有冒泡排序.快速排序.直接插入排 ...

  7. [C#][算法] 用菜鸟的思维学习算法 -- 马桶排序、冒泡排序和快速排序

    用菜鸟的思维学习算法 -- 马桶排序.冒泡排序和快速排序 [博主]反骨仔 [来源]http://www.cnblogs.com/liqingwen/p/4994261.html  目录 马桶排序(令人 ...

  8. 算法与数据结构(十三) 冒泡排序、插入排序、希尔排序、选择排序(Swift3.0版)

    本篇博客中的代码实现依然采用Swift3.0来实现.在前几篇博客连续的介绍了关于查找的相关内容, 大约包括线性数据结构的顺序查找.折半查找.插值查找.Fibonacci查找,还包括数结构的二叉排序树以 ...

  9. 算法与数据结构(七) AOV网的拓扑排序

    今天博客的内容依然与图有关,今天博客的主题是关于拓扑排序的.拓扑排序是基于AOV网的,关于AOV网的概念,我想引用下方这句话来介绍: AOV网:在现代化管理中,人们常用有向图来描述和分析一项工程的计划 ...

随机推荐

  1. Spring boot 1: 使用IDEA创建Spring boot项目

    项目用到的环境: Windows 10 JDK8 IntelliJ IDEA 2017.1.3 Apache Tomcat 8 Maven 3.3.3 使用IDEA新建spring boot项目 新建 ...

  2. 解决yii框架,gii脚手架不能使用。

    应用场景 把代码转移到线上服务器时,GII.BUG工具不正常使用,但在本地服务器是正常的. 分析原因 Yii框架在使用GII 和BUG 时,会针对访问IP地址拦截,没有在配置中设置的IP地址是会默认被 ...

  3. 【Android Developers Training】 67. 响应触摸事件

    注:本文翻译自Google官方的Android Developers Training文档,译者技术一般,由于喜爱安卓而产生了翻译的念头,纯属个人兴趣爱好. 原文链接:http://developer ...

  4. SpringMvc多视图配置(jsp、velocity、freemarker) velocity在springmvc.xml配置VelocityViewResolver,VelocityConfigurer,FreeMarkerConfigurer,FreeMarkerViewResolver

    ?xml version="1.0"encoding="UTF-8"?> <beans xmlns="http://www.springf ...

  5. usaco 2002 月赛 Fiber Communications 题解

    Description Farmer John wants to connect his N (1 <= N <= 1,000) barns (numbered 1..N) with a ...

  6. 学习笔记TF024:TensorFlow实现Softmax Regression(回归)识别手写数字

    TensorFlow实现Softmax Regression(回归)识别手写数字.MNIST(Mixed National Institute of Standards and Technology ...

  7. Oracle DECODE函数的用法详解

    Oracle DECODE函数使用方法: 1.比较大小select decode(sign(变量1-变量2),-1,变量1,变量2) from dual; --取较小值sign()函数根据某个值是0. ...

  8. 003.ASP.NET Core tutorials--【Asp.net core 教程】

    ASP.NET Core tutorials Asp.net core 教程 2016-10-14 1 分钟阅读时长 本文内容 1.Building web applications 构建web应用 ...

  9. Bootstrap按钮插件

    前面的话 按钮插件提供了一组可以控制按钮多种状态的功能,比如按钮的禁用状态.正在加载状态.正常状态等.本文将详细介绍Bootstrap按钮插件 加载状态 通过按钮可以设计状态提示,当单击按钮时,会显示 ...

  10. 说声PHP的setter&getter(魔术)方法,你们辛苦了

    php作为快速迭代项目的语言,其牛逼性质自不必多说.今天咱们要来说说php语言几个魔术方法,当然了,主要以setter&getter方法为主. 首先,咱们得知道什么叫魔术方法? 官方定义为:_ ...