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. 转化来的图标用法symbol引用‘font-class引用及Unicode引用

  2. Linux: Bash基本命令

    切换目录 cd 查看当前目录 pwd 生成目录 mkdir 搜索文件 查看当前的文件 ls 删除文件但保留特定类型 rm !(**) 例如: rm !(.tex|*.eps)其中,.tex, .eps ...

  3. Entity Framework入门教程:创建实体数据模型

    下图为一个已经创建好的数据库表关系 实体数据模型的创建过程 在Visual Studio项目中,右键程序集菜单,选择[添加]->[新建项],在[添加新项窗口]中选择[ADO.NET实体数据模型] ...

  4. Window文件目录挂载(mount)到linux系统目录下

    1.先在windows下面共享需要挂载的目录. 2.确保linux与windows是在同一个局域网当中. 3.在linux下面创建一个需要挂载到的目录. 4.然后点击"添加",建立 ...

  5. linux下安装apache最常见的报错解决

    报错如下: Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, ...

  6. Visual Studio Debugger中七个鲜为人知的小功能

    Visual Studio debugger是一个很棒的调试工具,可以帮助程序猿们快速地发现和解决问题.这里给大家简单介绍一下VS调试工具中的七个鲜为人知的小功能. 1.    一键跳转到指定语句 调 ...

  7. accp8.0转换教材第8章JavaScript对象及初识面向对象理解与练习

    JavaScript数据类型,对象,构造函数,原型对象,初识原型链,对象继承 一.单词部分 ①object父类②constructor构造函数③instance实例④call调用 ⑤apply应用⑥c ...

  8. maven配置本地仓库(从本地仓库下载jar包到.m2仓库)

     Windows-->preference               把你的settings.xml存到一个地方maven指向你的settings.xmlsettings.xml里的地址是你们 ...

  9. Python使用QRCode生成二维码

    PIL和QRCode下载地址: http://www.pythonware.com/products/pil/ https://pypi.python.org/pypi/qrcode/5.1 #你可能 ...

  10. usaco training 3.4.3 fence9 题解

    Electric Fence题解 Don Piele In this problem, `lattice points' in the plane are points with integer co ...