题意:给出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. JAVA 多线程轮流打印ABC

    采用Thread+Semaphore实现,思路很简单 import java.io.IOException; import java.util.concurrent.Semaphore; public ...

  2. d3.js学习笔记(五)——将数据结构化为D3.js可处理的

    目标 在这一章,你将会理解如何对数据进行结构化,来更好的使用D3.js. 我们将会回顾我们之前已经学习的,学习D3.js如何使用选集(selections),JavaScript对象基础,以及如何最优 ...

  3. MFC--串口编程---WIN API的方式将串扣操作封装在线程类中

    串口采集数据 本文档介绍的是如何获取串口原始数据并将原始数据解析成可处理或可展示的数据. 一.串口采集有很多方式: 1).MFC有一个专门的控件,直接编程采集,一个控件只能采集一个串口,而且串口名字比 ...

  4. 前端读取Excel报表文件 js-xlsx

    1.http://www.cnblogs.com/imwtr/p/6001480.html (前端读取Excel报表文件) 2.https://github.com/SheetJS/js-xlsx

  5. App如何推广秘籍之”渠道为王”

    现在市场上主流的APP从开发环境和搭载系统上来区分主要分为三种类型,它们是适用于iphone手机的ios版本.适用于安卓手机的 android版本和适用于window phone的WP8系统.由于每个 ...

  6. 【scala】集合框架

  7. input type=file 怎么样调取用户手机照相机

    input 有个属性accept="image/*" 这样就可以了,同时在网上看到了其他答案,试了下没啥效果.写记录下来 如下: 使用input:file标签, 去调用系统默认相机 ...

  8. LeetCode OJ:Best Time to Buy and Sell Stock(股票买卖的最佳时期)

    Say you have an array for which the ith element is the price of a given stock on day i. If you were ...

  9. VBox自动启动websrv 并开机启动所有的虚拟机

    由于项目需要,在Ubuntu 16.04的Server版本中安装了一个virtualbox,并利用phpvirtualbox来管理虚拟机 需要在宿主机启动之后将所有的虚拟机也启动,因此用以下方式进行处 ...

  10. 手把手教你怎么用ArcgisOnline发布地图服务

    Arcgis推出了Arcgis Online,但是大家都不知道这是个什么东西,怎么用这个东西,今天这篇文章手把手的教你如何使用Arcgisonline发布地图服务. 一.ArcgisOnline简介 ...