1047. Student List for Course (25)
来源:互联网 发布:网页代码编写软件 编辑:程序博客网 时间:2024/05/21 19:31
Zhejiang University has 40000 students and provides 2500 courses. Now given the registered course list of each student,you are supposed to output the student name lists of all the courses.
Input Specification:
Each input file contains one test case. For each case, the first line contains 2 numbers: N (<=40000), the total number of students, and K (<=2500), the total number of courses. Then N lines follow, each contains a student's name (3 capital English letters plus a one-digit number), a positive number C (<=20) which is the number of courses that this student has registered, and then followed by C course numbers. For the sake of simplicity, the courses are numbered from 1 to K.
Output Specification:
For each test case, print the student name lists of all the courses in increasing order of the course numbers. For each course, first print in one line the course number and the number of registered students, separated by a space. Then output the students' names in alphabetical order. Each name occupies a line.
Sample Input:10 5ZOE1 2 4 5ANN0 3 5 2 1BOB5 5 3 4 2 1 5JOE4 1 2JAY9 4 1 2 5 4FRA8 3 4 2 5DON2 2 4 5AMY7 1 5KAT3 3 5 4 2LOR6 4 2 4 1 5Sample Output:
1 4ANN0BOB5JAY9LOR62 7ANN0BOB5FRA8JAY9JOE4KAT3LOR63 1BOB54 7BOB5DON2FRA8JAY9KAT3LOR6ZOE15 9AMY7ANN0BOB5DON2FRA8JAY9KAT3LOR6ZOE1
提交代码
——————————
简单题目
注意的是,不能用string
#include <iostream>#include <vector>#include <algorithm>#include <cstring>using namespace std;/* run this program using the console pauser or add your own getch, system("pause") or input loop */int N,K;bool cmp(char a[], char b[]){return strcmp(a,b)<0;}int main(int argc, char** argv) {int i=0;scanf("%d %d",&N,&K);vector<int> course[K+1];//vector<charfor(i=0; i<N; i++){char tmp[5];int tmpname,size;scanf("%s %d",tmp,&size);tmpname=(tmp[0]-'A')*26*26*10+(tmp[1]-'A')*26*10+(tmp[2]-'A')*10+tmp[3]-'0';for(int j=0; j<size; j++){int c;scanf("%d",&c);course[c].push_back(tmpname);}}for(i=1; i<=K; i++){printf("%d %d\n",i,course[i].size());sort(course[i].begin(),course[i].end());for(int j=0; j<course[i].size(); j++){char tmp[5];int v=course[i][j];tmp[0]=v/(26*26*10)+'A';printf("%c",tmp[0]);tmp[1]=(v-(tmp[0]-'A')*26*26*10)/(26*10)+'A';printf("%c",tmp[1]);tmp[2]=(v-(tmp[0]-'A')*26*26*10-(tmp[1]-'A')*26*10)/10+'A';printf("%c",tmp[2]);tmp[3]=v%10+'0';printf("%c",tmp[3]);printf("\n");}}return 0;}
- 1047. Student List for Course (25)
- 1047. Student List for Course (25)-PAT
- 1047. Student List for Course (25)
- 【PAT】1047. Student List for Course (25)
- 1047. Student List for Course (25)
- 1047. Student List for Course (25)
- 1047. Student List for Course (25)
- 1047. Student List for Course (25)
- 1047. Student List for Course (25)
- 1047. Student List for Course (25)
- 1047. Student List for Course (25)
- 1047. Student List for Course (25)
- PAT 1047. Student List for Course (25)
- 1047. Student List for Course (25)
- 1047. Student List for Course (25)
- PAT 1047. Student List for Course (25)
- 1047. Student List for Course (25)
- 1047. Student List for Course (25)
- 字符串识别和过滤_华为SO挑战赛初赛试题2015年8月
- 基于eXosip的SIP客户端
- 数组
- OS-->使用GITHub搭建 个人(组织)网站 和 项目网站
- CSS制作图片水平垂直居中
- 1047. Student List for Course (25)
- 【OpenCV】边缘检测:Sobel、拉普拉斯算子
- soapUI接口测试工具所有版本下载地址
- Android ListView中使用CheckBox等的混乱问题
- Git 使用规范流程
- 高性能网站建设指南---前端工程师技能精髓--小记1
- the first day C++中结构体的使用
- 安卓更新界面问题
- 注视点估计(二维法)