题意是说有一些人参加了不同级别的班,级别有 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. 【洛谷U20626】gemo 容斥 FWT 高斯消元

    题目大意 给你一个无向图,有\(m\)个询问,每次给你一个点\(x\)和一个点集\(S\),问你从\(x\)开始走,每次从一个点随机的走到与这个点相邻的点,问你访问\(S\)中每个点至少一次的期望步数 ...

  2. os x && linux 文件传输基础命令

    一.从服务器下载文件到本机 1.修改文件所属 由于只能下载文件所属为自己的文件,所以要做修改文件所属的操作. chown hudelei /opt/logs/tomcat/app/tomcat_stk ...

  3. shell 中的 ${} 、## 、%% 使用范例

    日常使用范例见如下例子: 利用 ${ } 还可针对不同的变数状态赋值 (沒设定.空值.非空值): ${file-my.file.txt} :假如 $file 沒有设定,則使用 my.file.txt ...

  4. HNOI2019总结

    HNOI2019总结 Day 1 开场看三道题,T1是个计算几何,T2是个操作树加\(border\),T3题意有点复杂.想T1想了半个多小时,发现那个钝角不是很会处理,但是40分暴力应该还是可以写, ...

  5. 【BZOJ5416】【NOI2018】冒泡排序(动态规划)

    [BZOJ5416][NOI2018]冒泡排序(动态规划) 题面 BZOJ 洛谷 UOJ 题解 考场推出了就是两个上升子序列,并且最长下降子序列长度不超过\(2\)...然后大力暴力状压\(dp\)混 ...

  6. [luogu1337][bzoj3680][JSOI2004]平衡点 / 吊打XXX【模拟退火】

    题目描述 gty又虐了一场比赛,被虐的蒟蒻们决定吊打gty.gty见大势不好机智的分出了n个分身,但还是被人多势众的蒟蒻抓住了.蒟蒻们将n个gty吊在n根绳子上,每根绳子穿过天台的一个洞.这n根绳子有 ...

  7. nginx.conf(centos7 1.14)主配置文件修改

    #nginx1.14 centos7# For more information on configuration, see:# * Official English Documentation: h ...

  8. cf1088E Ehab and a component choosing problem (树形dp)

    题意(考试时看错了对着样例wa了好久..):从树上选k个连通块,使得权值的平均值最大的基础上,选的块数最多 如果不考虑块数最多的限制,肯定是只选一个权值最大的块是最好的 然后只要看这个权值最大的块有多 ...

  9. cf571B Minimization (dp)

    相当于是把%k相同的位置的数分为一组,组与组之间互不干扰 然后发现一组中可以任意打乱顺序,并且一定是单调排列最好,那个值就是最大值减最小值 所以我给所有数排序以后,同一组应该选连续的一段最好 然后发现 ...

  10. FZU 2150 Fire Game (bfs+dfs)

    Problem Description Fat brother and Maze are playing a kind of special (hentai) game on an N*M board ...