HUNNU--湖师大--11410--Eligibility

[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的位置找到他,完了,睡觉--!


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
if __name__ == '__main__': # -------------Adjustable global parameters---------- n=512 # pixel number m=10 # number of time phases angle = 5 # #sample points = 360/angle on the boundary numOfAngles = int(180/angle) numOfContourPts = int(360/angle) labelID = 1 # 勾画的RS文件中第几个轮廓为GTV # path of the input data folder = 'E:\\MedData\\4DCT-202305\\' #patient = '0007921948' # 缺少时间信息 patient = '0000726380' # 病人的编号 # 呼吸曲线数据文件 vxpPath = folder+patient+'\\0000726380\\0000726380_20230420_143723.vxp' # Save the generated figures to the latex file path figPath = "D:\\HUNNU\\Research\\DMD\\4D-CT\\latex-DMD插值\\modify202305\\figure\\" # -------------Auto generated global parameters---------- # 每个dicom文件包含多少横截面 name = os.listdir(folder+patient+'\\0') cuts = [] for i in range(len(name)): if 'CT' in name[i][0:2]: cuts.append(i+1) cuts = np.array(cuts) # phase name times = np.linspace(0,90,10) # image pixel coordinate nums = np.linspace(0,n-1,n) x,y = np.meshgrid(nums,nums) # 输出dicom头文件信息 filename = folder+patient+'\\0\\CT.{}'.format(patient)+'.Image 1.dcm' print('CT dicom file information:') info = loadFileInformation(filename) # 像素之间的间距,包括列间距和行间距,单位mm SliceThickness = info['SliceThickness'] # Z轴的扫描分辨率,单位mm pixelSpace = info['pixelSpace'] # 一个像素所占的实际体积 pixelVol = float(pixelSpace[0])*float(pixelSpace[0])*float(SliceThickness) print('sliceThickness=',SliceThickness,' pixelSpace=',pixelSpace)
06-02
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值