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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

【PAT甲级 vector string排序】1047 Student List for Course (25 分) 含别人的做法

發布時間:2024/2/28 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【PAT甲级 vector string排序】1047 Student List for Course (25 分) 含别人的做法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目


樣例輸出

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

題解1 C++

兩個測試用例不通過

#include<iostream> #include<algorithm> #include<string> #define STUSIZE 100 #define COUSIZE 100 using namespace std; class Course { public:string stu[STUSIZE];int size = 0; }; int cmp(string str1, string str2) {return str1 < str2; } int main() {int totalStu, totalCou;cin >> totalStu >> totalCou;Course course[COUSIZE];for (int i = 0; i < totalStu; i++) {string stuName;int stuCouTotal;cin >> stuName >> stuCouTotal;for (int j = 0; j < stuCouTotal; j++) {int couNum;cin >> couNum;course[couNum].stu[course[couNum].size] = stuName;course[couNum].size++;}}for (int i = 0; i < COUSIZE; i++) {if (course[i].size != 0) {sort(course[i].stu, course[i].stu + course[i].size,cmp);}}for (int i = 0; i < COUSIZE; i++) {if (course[i].size != 0) {cout << i << " " << course[i].size << "\n";for (int j = 0; j < course[i].size; j++) {cout << course[i].stu[j] << "\n";}}}system("pause"); }

題解2 C++

#include<cstdio> #include<iostream> #include<string> #include<vector> #include<algorithm> using namespace std; const int maxn = 2550; vector<string>course[maxn];int main() {int n, k;scanf("%d%d", &n, &k);for (int i = 1; i <= n; i++) {string name;int c, x;cin >> name >> c;for (int j = 0; j < c; j++) {scanf("%d", &x);course[x].push_back(name);}}for (int 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++) {printf("%s\n", course[i][j].c_str());}}return 0; }

總結

以上是生活随笔為你收集整理的【PAT甲级 vector string排序】1047 Student List for Course (25 分) 含别人的做法的全部內容,希望文章能夠幫你解決所遇到的問題。

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