[I] Eligibility

Regional Contest Director Osama Ismail knows that an individual cannot participate in the regional 
contest more than 5 times. Given a list of contestant names and the previous years they participated 

in, print which contestant is eligible.


Input Specification

The first line of the input contains a single integer T representing the number of the test cases

The first line of each test case contains a single integer N

N lines follow in this test case each having the format "Name Year" denoting that contestant Name 

participated in a regional contest in year Year

T ≤ 100

0 ≤ N ≤ 500

Name is sequence of lowercase English letters, spaces and contains up to 20 characters

1970 ≤ Year ≤ 2070

Note that since he collected the data from multiple sources it may contain duplicate records (if a 

contestant X have competed in year Y, you might find multiple lines "X Y" in the same test case)


Output Specification

For each test case, print a line containing the test case number as formatted in the sample and then 

for each eligible contestant print his\her name on a single line and note that you must print the names 

of the contestants in lexicographic order


Sample Input

1

6

ahmed 2010

ahmed 2011

ahmed 2009

ahmed 2008

ahmed 2005

mohamed 2001

Sample Output

Case #1:

mohamed

此题,水也,水题如何?比的就是方法,题意大概就是输入名字加上时间,每个人不许出现在不同的5个年份,排除之后还要字典序排序,亲们啊,听说名字和年份之间只有一个空格哦,听出我的意思了没?就是可能会有很多个空格,除了里年份最近的那个,其他都应该是名字的内容- -!

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
struct ssss    //杠杠滴直接结构体搞起
{
    char name[55];  //名字
    int len;  //名字这个字符串的总长度
}ss[555];
bool cmp(const ssss &a,const ssss &b)  //字典序排序的小sort函数--!
{
    if(strcmp(a.name,b.name)<0)return 1;  //非递增
    return 0;
}
int main (void)
{
    int t,n,i,j,k,l,flog,m=1;
    char s[55];
    scanf("%d",&t);
    while(t--&&scanf("%d%*c",&n))
    {
        for(i=0;i<n;i++)
        gets(ss[i].name),ss[i].len=strlen(ss[i].name);  //不知道名字尾端空格数,所以直接gets
        sort(ss,ss+n,cmp);  //排序时带上年龄直接排序,没影响
        for(i=0;i<n;i++)ss[i].name[ss[i].len-5]='\0';  //打断,就是把字符串最后的年份切出来,这可是我的精华啊--!
        cout<<"Case #"<<m++<<":"<<endl;
        for(i=k=0;i<n;i++)
        {
            if(i==0){strcpy(s,ss[i].name),k=1;continue;}  //第一次直接在s里面放进第一个名字,同时记录出现次数为1
            if(!strcmp(ss[i].name,ss[i-1].name))  //如果名字相同
            {
                if(strcmp(ss[i].name+ss[i].len-4,ss[i-1].name+ss[i].len-4))k++;  //如果年份不同就出现次数加一,先前是切断了,只是在名字最后面那个后面画上‘\0’,但是实际内存还是存在的,我只要能找到他的位置就可以再次利用他,就相当于年份被我变成了一个没有名字的静态字符串数组
            }
            else  //名字不同
            {
                if(k<5)cout<<s<<endl;  //如果没有出现5次以上就输出
                strcpy(s,ss[i].name);k=1;  //替换s,初始化k
            }
        }
        if(k<5)cout<<s<<endl;  //注意,最后那一个还是要考虑哦
    }
    return 0;
}

这里讲的就是对物理内存的运用的一个小技巧,文字永远比不上构图:s[111]

地址  1  2  3  4  5  6  7  8  9  10  11  12

内容  a  h  m e  d      2  0  1   0    \0   \0    //6下面是空格,不是空

然后被我折腾之后:

地址  1  2  3  4  5  6  7  8  9  10  11  12

内容  a  h  m e  d  \0 2  0  1   0    \0   \0    //6下面变成空

这样我要比较名字就直接调用s就好了,因为函数的停止是碰到\0的时候,所以我对s的抄作只会到地址5,但是后面的年份我还是要用的,有什么办法?先前不是保存了总长度的么?s[6]==s[总长度-4]?虽然后面的年份不属于s了,但是我可以根据他们相对于s的位置找到他,完了,睡觉--!

HUNNU--湖师大--11410--Eligibility的更多相关文章

  1. hunnu 11313 无重复元素序列的最长公共子序列转化成最长递增子序列 求法及证明

    题目:http://acm.hunnu.edu.cn/online/?action=problem&type=show&id=11313 湖师大的比赛,见我的另一篇水题题解,这里要说的 ...

  2. 华为云FusionInsight湖仓一体解决方案的前世今生

    摘要:华为云发布新一代智能数据湖华为云FusionInsight时再次提到了湖仓一体理念,那我们就来看看湖仓一体的来世今生. 伴随5G.大数据.AI.IoT的飞速发展,数据呈现大规模.多样性的极速增长 ...

  3. 为川师大女生支招 15年如何还200W

    就在昨儿一条新闻火遍全网,川师大21岁女生樊师贝发帖称,希望有人借她200万,为父母在城里买房15年还清,至于利息“可以用后半生来陪伴你”.她说,六旬父亲要负担家用,哥哥啃老,而她目前一分钱都还没挣到 ...

  4. hihoCoder 1425 : What a Beautiful Lake(美丽滴湖)

    hihoCoder #1425 : What a Beautiful Lake(美丽滴湖) 时间限制:1000ms 单点时限:1000ms 内存限制:256MB Description - 题目描述 ...

  5. 一塔湖图(codevs 1024)

    题目描述 Description 小松所在的PK大学校园又称作燕园,是一个十分美丽的校园.有博雅塔,未名湖,亚洲最大的高校图书馆,人称“一塔湖图”.但是由于燕园的历史比较悠久,所以很多的老房子都要不断 ...

  6. 湖大 11404 manacher

    链接   http://acm.hunnu.edu.cn/online/?action=problem&type=show&id=11404&courseid=0 求 最长回文 ...

  7. hunnu Sum of f(x)

    http://acm.hunnu.edu.cn/online/?action=problem&type=show&id=11546&courseid=0 Sum of f(x) ...

  8. hunnu 小明的烦恼——找字符串

    http://acm.hunnu.edu.cn/online/?action=problem&type=show&id=11544&courseid=0 小明的烦恼——找字符串 ...

  9. codevs1024一塔湖图(丧心病狂的建图)

    /* 丧心病狂的最短路 关键是建图 根据题目中给的路 拆出节点来 建图 (i,j) -->(j-1)*n+i 然后根据障碍 把死路 湖覆盖的dis改变成极大值 然后Floyd 然后 然后就没有然 ...

  10. python瓦登尔湖词频统计

    #瓦登尔湖词频统计: import string path = 'D:/python3/Walden.txt' with open(path,'r',encoding= 'utf-8') as tex ...

随机推荐

  1. left ,right ,cross ,full/left outer join/区别 详解

    --创建测试表wwif OBJECT_ID('qq') is not null drop table qqcreate table qq([序号] varchar(5),[内容1] varchar(1 ...

  2. 【转】 iOS开发 剖析网易新闻标签栏视图切换(addChildViewController属性介绍)

    原文:http://blog.csdn.net/hmt20130412/article/details/34523235 本来只是打算介绍一下addChildViewController这个方法的,正 ...

  3. firebug js版

    1.有些时候如 ie6 7 8 你觉得F12 不好用的话  你可以直接 把这两个js 引用到html 里面 <script src="https://getfirebug.com/fi ...

  4. 【C++学习之路】组合类的构造函数

    1 #include <iostream> using namespace std; class A { public: A(){ cout << "调用A无参&qu ...

  5. linux网络编程常用头文件

    sys/types.h:数据类型定义 sys/socket.h:提供socket函数及数据结构 netinet/in.h:定义数据结构sockaddr_in arpa/inet.h:提供IP地址转换函 ...

  6. 织梦dedecms网站六大SEO优化技巧(转帖)

    一个排名好的网站离不开好的cms,当然不同cms各有各的好处,因此我们在上线新网站的时候,要针对不同的情况因地制宜,选择不同的网站管理系统来做seo优化,现在使用比较流行的cms是织梦dedecms, ...

  7. VSS迁移

    今天花了一上午的时间,对VSS源代码库从一个服务器A上迁移到另一个服务器B上,包括修改历史.用户.以及权限.具体方法如下: 1.在服务器B上安装vss程序后,创建一database,并设置创建后的文件 ...

  8. 【行为型】Iterator模式

    迭代器模式提供一种方法顺序访问聚合对象中的各个元素,而又不需要暴露该聚合对象的内部表示.对于该模式,估计几乎所有的人都使用过,在此直接给出类结构图参考如下: 如前所述,迭代器模式的思想主要是:一能提供 ...

  9. Python学习笔记 :01概述

    Python基础 首先推荐学习Python基础的教程和书籍 视频教程推荐南京大学张莉老师在cousera上的教程用Python玩转数据 入门教程<Python基础教程> 数据挖掘教程< ...

  10. JS读取文件,Javascript之文件操作 (IE)

    一.功能实现核心:FileSystemObject 对象      要在javascript中实现文件操作功能,主要就是依靠FileSystemobject对象. 二.FileSystemObject ...