题意是说有一些人参加了不同级别的班,级别有 lower,middle,upper 三种,级别可以组合,出现比如 lower upper,middle upper 这种级别,级别的比较是从右往左,如果在一组比较中有的人的组合级别多,就以本组中级别最多的作为参照,其他人的级别要在左边添加 middle 来补到一样多。如果有人的级别是相等的,这些级别相等的人就按照名字的字典序排序。最后将排好序的名字依次输出。

开始本人的做法是将 lower,middle,upper 分别变成 1,2,3,然后从右向左将每个人的级别写成一个十进制的数,用 sort() 排序即可。

但是题中说每行不超过 256 个字符,也就是说级别数量会达到 50 个左右,写成一个数字很明显是存不下的,然后就糊涂了,竟然开始考虑用 4 进制来存,其实这里没有进位,和十进制是一样的长度,而且继续降低进制会反而将数字变长......

经高人指点,恍然大悟,原来可以直接开数组去存每一个数......

此外,在进行字典序排序的时候竟然不知道怎么写,其实可以直接比较 string 的,竟然还手写去连续比较了几位.......

题目代码如下:

 //#include <cstdio>
//#include <iostream>
//#include <algorithm>
//using namespace std;
//struct mem
//{
// string name,al;
// int cnt,sco,w[1050];
//}stu[1052];
//int n;
//bool cmp(mem a,mem b)
//{
// if(a.sco != b.sco)
// return a.sco < b.sco;
// else if(a.name[0] != b.name[0])
// return a.name[0] > b.name[0];
// else if(a.name[1] != b.name[1])
// return a.name[1] > b.name[1];
// else if(a.name[2] != b.name[2])
// return a.name[2] > b.name[2];
// else if(a.name[3] != b.name[3])
// return a.name[3] > b.name[3];
// return a.name[4] > b.name[4];
//}
//int main()
//{
// int len,big;
// bool f;
// scanf("%d",&n);
// getchar();
// big = -1000;
// for(int i = 0;i <n; i++)
// {
// getline(cin,stu[i].al);
// len = (stu[i].al).length();
// f = true;
// stu[i].cnt = 0;
// stu[i].sco = 0;
// for(int j = 0 ;j < len; j++)
// {
// if(stu[i].al[j] == ':') f = false;
//
// if(f) stu[i].name += stu[i].al[j];
// else{
// if(stu[i].al[j] == 'c') break;
// else if(stu[i].al[j] == 'u')
// {
// stu[i].w[stu[i].cnt++] = 3;
// j += 5;
// }
// else if(stu[i].al[j] == 'm')
// {
// stu[i].w[stu[i].cnt++] = 2;
// j += 6;
// }
// else if(stu[i].al[j] == 'o')
// {
// stu[i].w[stu[i].cnt++] = 1;
// j += 4;
// }
// }
// }
// if(stu[i].cnt > big) big = stu[i].cnt;
// }
// for(int i = 0 ; i < n;i++)
// {
// for(int j = stu[i].cnt-1; j >=0 ; j--)
// stu[i].sco = stu[i].w[j] + stu[i].sco *4;
// while(stu[i].cnt < big)
// {
// stu[i].sco = 2 + stu[i].sco*4;
// stu[i].cnt++;
// }
// }
// sort(stu,stu+n,cmp);
// for(int i = n-1 ; i >= 0; i--)
// cout << stu[i].name << endl;
// return 0;
//}
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
struct node
{
char name[];
char lever[];
char sco[];
} stu[];
bool cmp(struct node a,struct node b)
{
if(strcmp(a.sco,b.sco) != ) return (strcmp(a.sco,b.sco) > );
return strcmp(a.name,b.name) < ;
}
void rev(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 cnt,n;
scanf("%d",&n);
for(int i = ; i < n; i++)
{
cnt = ;
scanf("%s",stu[i].name);
int str = strlen(stu[i].name);
stu[i].name[str-] = ;
for(int j = ; j < ; j++)
{
if(j == ) stu[i].sco[j] = ;
else stu[i].sco[j] = '';
}
while()
{
scanf("%s",stu[i].lever);
if(strcmp("upper",stu[i].lever)==) stu[i].sco[cnt++]='';
if(strcmp("middle",stu[i].lever)==) stu[i].sco[cnt++]='';
if(strcmp("lower",stu[i].lever)==) stu[i].sco[cnt++]='';
if(strcmp("class",stu[i].lever)==) break;
}
rev(stu[i].sco,cnt);
}
sort(stu,stu+n,cmp);
for(int i=; i<n; i++) printf("%s\n",stu[i].name);
return ;
}

Gym 100820C(级别排序 **)的更多相关文章

  1. 2016"百度之星" - 初赛(Astar Round2A)Gym Class(拓扑排序)

    Gym Class  Accepts: 849  Submissions: 4247  Time Limit: 6000/1000 MS (Java/Others)  Memory Limit: 65 ...

  2. 2016"百度之星" - 初赛(Astar Round2A) 1006 Gym Class 拓扑排序

    Gym Class  Time Limit: 6000/1000 MS (Java/Others)  Memory Limit: 65536/65536 K (Java/Others) Problem ...

  3. HDU 5695 Gym Class 拓扑排序

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5695 题解: 求出字典序最大的拓扑序.然后把求好的数列翻转过来就是满足条件的数列,然后模拟求一下va ...

  4. spark高级排序彻底解秘

    排序,真的非常重要! RDD.scala(源码) 在其,没有罗列排序,不是说它不重要! 1.基础排序算法实战 2.二次排序算法实战 3.更高级别排序算法 4.排序算法内幕解密 1.基础排序算法实战 启 ...

  5. Java:集合,对列表(List)中的自定义对象按属性(字段)排序(正序、倒序)的方法

    1. 要求 对列表(List)中的自定义对象,要求能够按照对象的属性(字段)进行排序(正序.倒序). 如:用户对象(Member)有用户名(username).级别(level).出生日期(birth ...

  6. 我的Java开发学习之旅------>Java利用Comparator接口对多个排序条件进行处理

    一需求 二实现Comparator接口 三验证排序结果 验证第一条件首先按级别排序级别最高的排在前面 验证第二条如果级别相等那么按工资排序工资高的排在前面 验证第三条如果工资相当则按入职年数排序入职时 ...

  7. 扩增子图表解读4曼哈顿图:差异分类级别Taxonomy

    曼哈顿图 Manhattan Plot 曼哈顿图本质上是一个散点图,用于显示大量非零大范围波动数值,最早应用于全基因组关联分析(GWAS)研究展示高度相关位点.它得名源于样式与曼哈顿天际线相似(如下图 ...

  8. 关于logback日志级别的配置

    logback如果需要灵活的配置日志级别,需要结合过滤器,<filter></fiter>这个标签.需要注意的是,过滤器过滤的基础是在root标签的配置基础上进行的. 过滤器可 ...

  9. Python数据类型之“序列概述与基本序列类型(Basic Sequences)”

    序列是指有序的队列,重点在"有序". 一.Python中序列的分类 Python中的序列主要以下几种类型: 3种基本序列类型(Basic Sequence Types):list. ...

随机推荐

  1. hdu 1540 Tunnel Warfare(Treap)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=1540 思路:三种操作: D摧毁一个点 R重建最晚被修改的那个点 Q询问点x联通的点有多少个 逆向思维,D操 ...

  2. IDEA如何查看maven的依赖结构

    打开方式: 方法一:该工具有个Maven Projects窗口,一般在右侧能够找到,如果没有可以从菜单栏打开:View>Tool Windows>Maven Projects:选择要分析的 ...

  3. Java的equals方法,首先要判断类型是否相同

    如下代码,Long 和Integer 进行比较: Integer aa = 1; Long bb= 1L; System.out.println(aa.equals(bb)); 输出为:false 查 ...

  4. XAMPP Access forbidden! Error 403,You don't have permission to access the requested directory

    xampp 无论在window 还是在 Mac 如出现以下错误的:通常的解决方式: 具体配置教程可以任意查相关资料既可,(配置子站子大致流程如:开启httpd.conf的inc...httpd-vho ...

  5. [luogu2503][HAOI2006]均分数据【模拟退火】

    题目描述 已知N个正整数:A1.A2.--.An .今要将它们分成M组,使得各组数据的数值和最平均,即各组的均方差最小.均方差公式如下: 分析 模拟退火学习笔记:https://www.cnblogs ...

  6. 【转】设置 vim 显示行号永久有效

    在linux环境下,vim是常用的代码查看和编辑工具.在程序编译出错时,一般会提示出错的行号,但是用vim打开的代码确不显示行号,错误语句的定位非常不便.那么怎样才能让vim显示代码的行号呢? 1 临 ...

  7. 两数之和 II - 输入有序数组

    题目描述 给定一个已按照升序排列 的有序数组,找到两个数使得它们相加之和等于目标数. 函数应该返回这两个下标值 index1 和 index2,其中 index1 必须小于 index2. 说明: 返 ...

  8. 牛客练习赛28 B数据结构(线段树)

    链接:https://www.nowcoder.com/acm/contest/200/B来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言5242 ...

  9. HDU--5269 ZYB loves Xor I (字典树)

    题目电波: HDU--5269 ZYB loves Xor I 首先我们先解决 ai xor aj 每个数转化为二进制  我们用字典树统计 每个节点 0 和 1 的出现的个数 #include< ...

  10. MySQL 到底能不能放到 Docker 里跑?

    https://weibo.com/ttarticle/p/show?id=2309404296528549285581 前言 前几月经常看到有 MySQL 到底能不能放到 Docker 里跑的各种讨 ...