【1047】Student List for Course (25 分)

简介: 【1047】Student List for Course (25 分)【1047】Student List for Course (25 分)
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<algorithm>  
#include<map>
#include<vector>
#include<queue> 
using namespace std;  
const int maxn=40010; //最大学生人数
const int maxc=2510;  //最大课程门数
char name[maxn][5]; //maxn个学生
vector<int> course[maxc]; //course[i]存放第i门课的所有学生编号
//注意上面的是vector数组
bool cmp(int a,int b){
  return strcmp(name[a],name[b])<0; //按姓名字典序从小到大排序
}
int main(){   
  int n,k,c,courseID;
  scanf("%d%d",&n,&k);  //学生人数及课程数
  for(int i=0;i<n;i++){ //对每个学生进行遍历
    scanf("%s %d",name[i],&c);
    for(int j=0;j<c;j++){  //遍历每个学生的课程编号
      scanf("%d",&courseID);  
      course[courseID].push_back(i); //将学生i加入第courseID门课中
    }
  }
  //输出操作
  for(int i=1;i<=k;i++){
    printf("%d %d\n",i,course[i].size()); //第i门课的学生数
    sort(course[i].begin() , course[i].end(), cmp);//对第i门课的学生排序
    for(int j=0;  j<course[i].size()  ; j++){
      printf("%s\n",name[ course[i][j]  ]); //输出学生姓名
    }
  }
  system("pause");
    return 0;   
}
相关文章
|
存储 C++
【PAT甲级 - C++题解】1047 Student List for Course
【PAT甲级 - C++题解】1047 Student List for Course
60 1
|
存储 C++
【PAT甲级 - C++题解】1039 Course List for Student
【PAT甲级 - C++题解】1039 Course List for Student
60 0
PAT (Advanced Level) Practice - 1039 Course List for Student(25 分)
PAT (Advanced Level) Practice - 1039 Course List for Student(25 分)
84 0
|
Java Scala Python
scala调用java的方法,返回了一个对象链表List<Student>,在scala中遍历该链表获取指定Student的名字name
假设Student类如下: class Student { private int no; private String name; public int getNo() { return no; } public String getName() { return n...
1547 0
|
2月前
|
安全 Java
java线程之List集合并发安全问题及解决方案
java线程之List集合并发安全问题及解决方案
181 1
|
20天前
|
Java API Apache
怎么在在 Java 中对List进行分区
本文介绍了如何将列表拆分为给定大小的子列表。尽管标准Java集合API未直接支持此功能,但Guava和Apache Commons Collections提供了相关API。
|
24天前
|
运维 关系型数据库 Java
PolarDB产品使用问题之使用List或Range分区表时,Java代码是否需要进行改动
PolarDB产品使用合集涵盖了从创建与管理、数据管理、性能优化与诊断、安全与合规到生态与集成、运维与支持等全方位的功能和服务,旨在帮助企业轻松构建高可用、高性能且易于管理的数据库环境,满足不同业务场景的需求。用户可以通过阿里云控制台、API、SDK等方式便捷地使用这些功能,实现数据库的高效运维与持续优化。
|
1月前
|
存储 安全 Java
详解Java中集合的List接口实现的ArrayList方法 | Set接口实现的HashSet方法
详解Java中集合的List接口实现的ArrayList方法 | Set接口实现的HashSet方法
|
2月前
|
Java API
使用 Java 来实现两个 List 的差集操作
使用 Java 来实现两个 List 的差集操作
30 3
|
1月前
|
存储 Java 索引
Java List接口实现原理与性能评估
Java List接口实现原理与性能评估