题意:给出K门课程(编号1~K)以及报名该课程的学生,然后有N个学生查询,对于每一个查询,输出该学生所报的相关课程编号,且要求编号按增序输出。

思路:题目不难,解析略。(本来用map直接映射,用STL的string存储姓名是会超时的,结果今天再测了一下结果能AC了,什么鬼!?)考试时,如果只是纯映射关系,无需键值有序,可以用unordered_map,头文件在<unordered_map>下,如果会超时再尝试字符串哈希的方法。简单的字符串哈希就是下面的change()函数,需记住。

代码:

#include <cstdio>
#include <cstring>
#include <set>
using namespace std;
***+;
set<int> stu[N];//stu[i]存放学生所选择的课程编号,利用set的自动排序

//将字符串映射成数字
int change(const char *str)
{
    ,i=;
    int len=strlen(str);
    ;i++)
        id=*id+(str[i]-'A');
    id=id*+str[i]-';
    return id;
}

int main()
{
    int queryCnt,k;
    scanf("%d%d",&queryCnt,&k);
    int courseid,m;
    ];
    ;i<=k;i++){
        scanf("%d%d",&courseid,&m);
        while(m){
            scanf("%s",name);
            int id=change(name);
            stu[id].insert(courseid);
            m--;
        }
    }
    ;i<queryCnt;i++){
        scanf("%s",name);
        int id=change(name);
        printf("%s %d",name,stu[id].size());
        for(auto it:stu[id]) printf(" %d",it);
        printf("\n");
    }
    ;
}

1039 Course List for Student的更多相关文章

  1. 1039. Course List for Student (25)

    题目链接:http://www.patest.cn/contests/pat-a-practise/1039 题目: 1039. Course List for Student (25) 时间限制 2 ...

  2. PAT 1039 Course List for Student[难]

    1039 Course List for Student (25 分) Zhejiang University has 40000 students and provides 2500 courses ...

  3. PAT 甲级 1039 Course List for Student (25 分)(字符串哈希,优先队列,没想到是哈希)*

    1039 Course List for Student (25 分)   Zhejiang University has 40000 students and provides 2500 cours ...

  4. PAT 1039. Course List for Student

    Zhejiang University has 40000 students and provides 2500 courses. Now given the student name lists o ...

  5. 1039 Course List for Student (25分)

    Zhejiang University has 40000 students and provides 2500 courses. Now given the student name lists o ...

  6. PAT 1039 Course List for Student (25分) 使用map<string, vector<int>>

    题目 Zhejiang University has 40000 students and provides 2500 courses. Now given the student name list ...

  7. PAT甲题题解-1039. Course List for Student (25)-建立映射+vector

    博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789157.html特别不喜欢那些随便转载别人的原创文章又不给 ...

  8. PAT (Advanced Level) 1039. Course List for Student (25)

    map会超时,二分吧... #include<iostream> #include<cstring> #include<cmath> #include<alg ...

  9. 【PAT甲级】1039 Course List for Student (25 分)(vector嵌套于map,段错误原因未知)

    题意: 输入两个正整数N和K(N<=40000,K<=2500),分别为学生和课程的数量.接下来输入K门课的信息,先输入每门课的ID再输入有多少学生选了这门课,接下来输入学生们的ID.最后 ...

随机推荐

  1. jquery的50个免费插件

    说不定什么时候用到呢 http://www.admin10000.com/document/4711.html

  2. 【C#笔札】1 string类型

    C中没有string这个类型,而是用字符串数组来实现,相对来说比较麻烦. LABVIEW相对来说要简单太多,毕竟他主要的精力集中在硬件控制上,软件操作方面极其简单. C#类似,C#中有System.S ...

  3. Load事件

    Load事件 在 窗体完全呈现之后 被 触发 如下伪代码: void  ShowWindows { .....//显示父容器 .....//显示子容器 .....//显示控件 //至此,窗体完全呈现 ...

  4. 探究platform_driver中“多态”思想

    问题最初是下面的两段代码引出的: static struct platform_driver sonypi_driver = { .driver = { .name = "sonypi&qu ...

  5. IOS-第三方(SDWebImage)

    SDWebImage ReadMe.md 文档 附:SDWebImage框架github下载地址:https://github.com/rs/SDWebImage注1:该文章简单翻译了SDWebIma ...

  6. 【sparkStreaming】kafka作为数据源的生产和消费

    1.建立生产者发送数据 (1)配置zookeeper属性信息props (2)通过 new KafkaProducer[KeyType,ValueType](props) 建立producer (3) ...

  7. VS2017 Product Key

    Enterprise: NJVYC-BMHX2-G77MM-4XJMR-6Q8QF Professional: KBJFW-NXHK6-W4WJM-CRMQB-G3CDH

  8. 重读tcp-ip详解三卷:1

    应用层 Http.Telnet.FTP和e-mail等 负责把数据传输到传输层或接收从传输层返回的数据传输层 TCP和UDP 主要为两台主机上的应用程序提供端到端的通信,TCP为两台主机提供高可靠性的 ...

  9. 修改CentOS7网卡名称为传统名称eth0格式

    1.调整网卡名称 进入网卡目录```[root@tools]# cd/etc/sysconfig/network-scripts/``` 修改名称```[root@network-scripts]# ...

  10. mysql 视图,触发器,存储

    一.视图 概念:其实就是一个临时表. 视图是一个虚拟表(非真实存在的),其本质是[根据SQL语句获取动态的数据库,并为其命名],用户使用时只需使用[名称]即可获取结果集.就可以当做表来使用. # 1. ...