PAT 甲级 A1039 (2019/02/22)

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
const int MAXN = 40010;
const int MAXM = 26*26*26*10 + 1;
vector<int> selectCourses[MAXM];
//vector数组,selectCourses[0] ~ selectCourses[MAXM - 1]中的每一个都是一个容器
int getID(char name[]){
    int ID = 0;
    for(int i = 0; i < 3; i++){
        ID = ID * 26 + (name[i] - 'A');
    }
    return ID * 10 + (name[3] - '0');
}
int main(){
    int N, K;
    scanf("%d %d", &N, &K);     //人数及选课数
    for(int i = 0; i < K; i++){
        int courseIndex, stuNumber;
        scanf("%d %d", &courseIndex, &stuNumber);   //输入课程编号及选课人数
        for(int j = 0; j < stuNumber; j++){
            char StuName[5];
            scanf("%s", StuName);   //输入选课学生姓名
            int StuID = getID(StuName);     //将姓名散列为一个整数作为编号
            selectCourses[StuID].push_back(courseIndex);    //将课程编号加入学生选课数组
        }
    }
    for(int k = 0; k < N; k++){ //N个查询
        char StuName[5];
        scanf("%s", StuName);   //学生姓名
        int getStuID = getID(StuName);  //获得学生编号
        sort(selectCourses[getStuID].begin(), selectCourses[getStuID].end());   //从小到大排序
        printf("%s %d", StuName, selectCourses[getStuID].size());   //姓名,选课数
        for(int l = 0; l < selectCourses[getStuID].size(); l++){
            printf(" %d",selectCourses[getStuID][l]);   //选课编号
        }
        printf("\n");
    }
    return 0;
}

原文地址:https://www.cnblogs.com/zjsaipplp/p/10425228.html

时间: 2024-08-30 16:58:32

PAT 甲级 A1039 (2019/02/22)的相关文章

PAT 甲级 A1060 (2019/02/22)

1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 using namespace std; 5 int n; 6 string Deal(string S, int &e){ 7 int k = 0; //s的下标 8 while(S.length() > 0 && S[0] == '0'){ 9 S.erase(S.begin()); //去掉S的前导0 10 }

PAT 甲级 A1100 (2019/02/22)

1 #include<cstdio> 2 #include<iostream> 3 #include<string> 4 #include<map> 5 using namespace std; 6 // [0,12]的火星文 7 string unitDigit[13] = { 8 "tret", "jan", "feb", "mar", "apr", &q

PAT 甲级 A1047 (2019/02/22)

#include<cstdio> #include<cstring> #include<algorithm> #include<vector> using namespace std; const int MAXN = 40010; const int MAXC = 2510; vector<int> Courses[MAXC]; char StuName[MAXN][5]; bool cmp(int a, int b){ //按照名字典序从小到

PAT 甲级 A1063 (2019/02/22)

#include<cstdio> #include<set> using namespace std; const int MAXN = 51; set<int> ST[MAXN]; //MAXN个集合 void compare(int x, int y){ //比较集合 ST[x] 和 ST[y] int DiffNumber = ST[y].size(), SameNumber = 0; //不同数的个数,相同数的个数 //遍历集合 ST[x] for(set<

PAT甲级【2019年3月考题】——A1158 TelefraudDetection【25】

Telefraud(电信诈骗) remains a common and persistent problem in our society. In some cases, unsuspecting victims lose their entire life savings. To stop this crime, you are supposed to write a program to detect those suspects from a huge amount of phone c

PAT甲级1005 Spell It Right

题目:PAT甲级 1005 题解:水题.看到题目的第一时间就在想一位一位的mod,最后一加一转换就完事了.结果看到了N最大为10的100的次方,吓得我赶紧放弃这个想法... 发现碰到这种情况用字符串十分好用,这道题应该考察的就是这一点.大致思路就是把数字的每一位放到字符串中,然后通过ASCII码得到每一位的相加结果num,然后把num一位一位的放到stack中,使用stack是因为它先进先出的特性,最后输出就行了. 代码: 1 #include<cstdio> 2 #include<qu

【谜客帝国】第147届月思主擂谜会(2019.02.15)

 [谜客帝国]第147届月思主擂谜会(2019.02.15) 主持计分:东东 1.“人在中天日月间”(9笔字)春/月思 [注:面出陈孚<开平即事二首>,“势超大地山河上,-.”] 2. 玉漏声中烟气袅(3字法国奢侈品牌)YSL/月思 3. 双双相念初相爱(2字著名动漫人物)菜菜/月思 4.“数点燕云州外.雪霜威”(足球用语二,4+3)4132.451/月思 [注:面出余文<相见欢>,“登高望断龙旗,未曾归.几度中原北定,梦依稀.朔风乱,胡尘漫,掩斜晖.-.”] 5.“十载同心如一人

2019.6.22刷题统计

今日写统计如此早的原因是:下午回老家,无法刷题. 今天完成了普及组的100道题,但还未进入USACO. 通过数:9 通过题目编号:1061/1072/1085/1090/1103/1109/1113/1125/1132 排名:暂居第一 本网站开始时间:2019/6/15 15:02:09 结束时间:2019/6/22 12:58:30 共计6天21小时56分21秒. 完成题目(见图片): 通过普及组100题的练习,我发现了自己普及组的知识点仍然掌握不全面,还需要继续复习. 另外,已经完成了入门+

PAT甲级考前整理

终于在考前,刷完PAT甲级130道题目,不容易!!!每天沉迷在刷题之中而不能超脱,也是一种境界.PAT甲级题目总的说卡题目的比较多,卡测试点的比较少,有些题目还会有题意混淆,这点就不吐槽了吧.静下心来耍这130道题,其实磨练的是一种态度与手感,养成的是一种习惯.热爱AC没有错!! 130道题目主要的考点: 1.排序:快速排序,直接插入排序,希尔排序,分治排序,堆排序. 2.图论:拓扑排序.最短路径.深度搜索.广度搜索. 3.树:树的遍历.完全二叉树.AVL. 4.其他:并查集,模拟,哈希.背包.