A1047 Student List for Course (25 分)
一、技术总结
- 首先题目要看清湖,提出的条件很关键,比如for循环的终止条件,特别注意。
- 还有这个题目主要考虑到vector的使用,还有注意一定要加上using namespace std;
- 输出格式,题目中如果没有要求什么最后一行不能有空格什么的,就不要画蛇添足,按照正常的换行就行。
- 这里采用的是先使用二维字符串数组存储名字,然后名字也有编号,使用这个编号来记录每个课程中选取的学生,巧妙的避免了要记录下字符串的尴尬局面。然后再开辟一个vector容器来记录课程中选课学生的编号,最后排序即可。
- 如果很大的字符串存储,不要使用string,要使用char数组,可以是二维的。然后如果要比较字符串的大小,按字母从小到大使用cmp如下:
bool cmp(int a, int b){
//这里是按字符串从小到大,如果相反改变下面中小于号为大于号即可,同时stu是提前声明的全局变量二维字符串数组
return strcmp(stu[a], stu[b]) < 0;
}
二、参考代码
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 40010;
const int K = 2510;
char stu[N][5];
vector<int> q[K];
bool cmp(int a, int b){
return strcmp(stu[a], stu[b]) < 0;
}
int main(){
int n,k;
scanf("%d%d", &n, &k);
int num = 0;
int course = 0;
for(int i = 0; i < n; i++){
scanf("%s %d", stu[i], &num);
for(int j = 0; j < num; j++){
scanf("%d", &course);
q[course].push_back(i);
}
}
for(int i = 1; i <= k; i++){
sort(q[i].begin(), q[i].end(), cmp);
printf("%d %d\n", i, q[i].size());
for(int j = 0; j < q[i].size(); j++){
printf("%s\n", stu[q[i][j]]);
}
}
return 0;
}
A1047 Student List for Course (25 分)的更多相关文章
- PAT 甲级 1047 Student List for Course (25 分)(cout超时,string scanf printf注意点,字符串哈希反哈希)
1047 Student List for Course (25 分) Zhejiang University has 40,000 students and provides 2,500 cou ...
- 1047 Student List for Course (25分)
Zhejiang University has 40,000 students and provides 2,500 courses. Now given the registered course ...
- 【PAT甲级】1047 Student List for Course (25 分)
题意: 输入两个正整数N和K(N<=40000,K<=2500),接下来输入N行,每行包括一个学生的名字和所选课程的门数,接着输入每门所选课程的序号.输出每门课程有多少学生选择并按字典序输 ...
- PAT 甲级 1039 Course List for Student (25 分)(字符串哈希,优先队列,没想到是哈希)*
1039 Course List for Student (25 分) Zhejiang University has 40000 students and provides 2500 cours ...
- PAT 甲级 1083 List Grades (25 分)
1083 List Grades (25 分) Given a list of N student records with name, ID and grade. You are supposed ...
- 1109 Group Photo (25 分)
1109 Group Photo (25 分) Formation is very important when taking a group photo. Given the rules of fo ...
- 1012 The Best Rank (25 分)
1012 The Best Rank (25 分) To evaluate the performance of our first year CS majored students, we cons ...
- 1036 Boys vs Girls (25 分)
1036 Boys vs Girls (25 分) This time you are asked to tell the difference between the lowest grade of ...
- A1083 List Grades (25)(25 分)
A1083 List Grades (25)(25 分) Given a list of N student records with name, ID and grade. You are supp ...
随机推荐
- 给Java0基础的五个学习的思路?
关于Java初学者来说,想学习Java教程,需求了解,根底打好才干学得更好,Java教程之学习Java的路线图的五个必经阶段,希望能对Java学习者有所帮忙. 第一个阶段-java根底阶段 1.jav ...
- IDEA2019 Win10 Tomcat Server控制台中文乱码的快速解决办法
原理 Windows10的控制台使用GBK编码,而Tomcat使用UTF-8编码,导致乱码 解决办法 修改$tomcat/conf/logging.properties文件 # 注释这行 java.u ...
- CF1244C The Football Season
题目链接 problem 给定\(n,p,w,d\),求解任意一对\((x,y)\)满足\[xw+yd=p\\ x + y \le n\] \(1\le n\le 10^{12},0\le p\le ...
- 【PAT甲级】Public Bike Management 题解
题目描述 There is a public bike service in Hangzhou City which provides great convenience to the tourist ...
- 在dubbo的一端,看Netty处理数据包,揭网络传输原理
如今,我们想要开发一个网络应用,那是相当地方便.不过就是引入一个框架,然后设置些参数,然后写写业务代码就搞定了. 写业务代码自然很重要,但是你知道: 你的数据是怎么来的吗?通过网络传输过来的呗. 你知 ...
- 使用C#+Edge (Chromium)进行Web自动化测试
今天看到了VisualStudio中现在已经自带了Web单元测试项目模板,便试了一下,发现还比较好用,它默认的是Selenium实现的,测试组在用Selenium+Python来写过自动化测试,原来它 ...
- c# 字符串中全角和半角字符互转
public class ConvertDBCAndSBC { /// <summary>半角转成全角 /// 半角空格32,全角空格12288 /// 其他字符半角33~126,其他字符 ...
- Python爬虫:设置Cookie解决网站拦截并爬取蚂蚁短租
前言 文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者: Eastmount PS:如有需要Python学习资料的小伙伴可以加 ...
- 垃圾分类环保宣传 PPT模板
模板来源:http://ppt.dede58.com/peixunyanjiang/26263.html
- shell 编程练习题2
需求1:使用root用户清空/var/log/messages日志,并每次执行保留最近100行 1.必须是root用户 2.需要保留最后100行 [root@manager if]# cat ...