日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

1047. Student List for Course (25)

發布時間:2024/4/17 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 1047. Student List for Course (25) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目例如以下:

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 5 ZOE1 2 4 5 ANN0 3 5 2 1 BOB5 5 3 4 2 1 5 JOE4 1 2 JAY9 4 1 2 5 4 FRA8 3 4 2 5 DON2 2 4 5 AMY7 1 5 KAT3 3 5 4 2 LOR6 4 2 4 1 5 Sample Output: 1 4 ANN0 BOB5 JAY9 LOR6 2 7 ANN0 BOB5 FRA8 JAY9 JOE4 KAT3 LOR6 3 1 BOB5 4 7 BOB5 DON2 FRA8 JAY9 KAT3 LOR6 ZOE1 5 9 AMY7 ANN0 BOB5 DON2 FRA8 JAY9 KAT3 LOR6 ZOE1

這是一道比較簡單的統計、輸出題目,由于輸出不涉及查詢,而是順序輸出。因此不必使用map進行倒排索引。僅僅須要給每門課一個vector<char*>,把全部選這門課的人壓入對應容器,然后按字典序排序,最后輸出。

須要注意的是。對于字符處理的題目,要盡量使用char*而避免使用string,盡管string非常方便,可是對于string的比較和拷貝操作會消耗大量時間。easy超時。

char*沒有string好用,可是在c++特性下我么能夠使用char* name = new char[4];來創建一個剛好容納名字的空間,然后把它壓入容器中。

對于char*的比較,剛開始我使用的是strcmp,可是它是s1<s2返回-1,s1==s2返回0,s1>s2返回1,而sort函數默認使用<比較,返回1代表滿足,因此二者不是非常匹配,我最后採用了手動比較每一位的方法。

代碼例如以下:

#include <iostream> #include <stdio.h> #include <stdlib.h> #include <map> #include <vector> #include <string> #include <string.h> #include <algorithm>using namespace std;int compare(const char *name1, const char *name2){for(int i = 0; i < 4; i++){if(name1[i] < name2[i]){return 1;}else if(name1[i] == name2[i]){continue;}else{return 0;}}}int main() {int N,K,C,num;cin >> N >> K;vector<vector<char*> > course(K+1);for(int i = 0; i < N; i++){char* name = new char[4];scanf("%s%d",name,&C);for(int j = 0; j < C; j++){scanf("%d",&num);course[num].push_back(name);}}for(int j = 1; j <= K; j++){sort(course[j].begin(),course[j].end(),compare);printf("%d %d\n",j,course[j].size());for(int k = 0; k < course[j].size(); k++){printf("%s\n",course[j][k]);}}return 0; }

總結

以上是生活随笔為你收集整理的1047. Student List for Course (25)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 无码人中文字幕 | 国产夫妻性生活视频 | xxx久久| 欧美激情在线观看 | 国产视频分类 | 男女无遮挡做爰猛烈视频 | 国产不卡精品视频 | 国产精品入口久久 | 男女裸体无遮挡做爰 | 污片网站在线观看 | 天天射日日射 | 五十路av在线 | 天天欧美| 日韩喷潮 | 中文字幕成人 | 免费黄网在线看 | 国产一区在线不卡 | 亚洲av无码乱码国产精品 | 色香av| 久久黄色一级 | 国产精品探花一区二区三区 | 按摩毛片 | 绿帽在线 | 免费日韩视频 | 亚洲一区二区免费在线观看 | 久久人爽| 久久久久久久久网站 | 91久久精品美女高潮 | 国产伦精品视频一区二区三区 | 亚洲欧美成人综合 | 182av| 国产盗摄精品 | аⅴ资源中文在线天堂 | 国产在线精品福利 | 国产av自拍一区 | av网站在线免费 | 男男毛片 | 国产美女精品视频国产 | 亚洲毛片在线播放 | 欧洲美熟女乱又伦 | 久久久久久艹 | 午夜视频网 | 天天射天天操天天干 | 91视频久久 | 日本少妇网站 | 黄色理论片| 好姑娘在线观看高清完整版电影 | 欧美日韩高清在线观看 | 羽月希奶水一区二区三区 | 色欧美视频 | 超污视频软件 | 欧美亚色 | 69天堂| caoporen超碰| 精品无码av一区二区三区不卡 | 免费国产黄色片 | 人妻丝袜一区 | 辟里啪啦国语版免费观看 | 欧美aa| 一道本无吗一区 | 麻豆一区二区在线 | 一区二区三区视频观看 | 天天av天天 | 久久免费片 | 日本xxxxxxxxx| 超级黄色录像 | 97自拍视频 | 国产无套内射又大又猛又粗又爽 | 亚洲女人在线 | 中文字幕一区在线播放 | 免费黄色一级大片 | 狠狠操夜夜操 | 亚洲视频 欧美视频 | 欧美国产大片 | 久久99国产视频 | 无码熟妇人妻av | 香蕉久久精品日日躁夜夜躁 | 果冻传媒av | 欧美在线不卡视频 | 色综合久久久无码中文字幕波多 | 国产区久久 | 超碰在线c | 三级理论电影 | 久久综合91 | 亚洲妇熟xx妇色黄蜜桃 | 被黑人各种姿势猛c哭h文1 | 亚洲一级理论片 | 国产一级片a | 国产亚洲自拍一区 | 免费午夜影院 | 玉女心经是什么意思 | 久久精品这里只有精品 | 精品无码一区二区三区 | 欧美综合社区 | av不卡高清| 亚洲成人7777 | 九一国产在线 | 无码人妻精品一区二区蜜桃网站 | 成人影视在线播放 |