1039 Course List for Student

Posted huhusw

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了1039 Course List for Student相关的知识,希望对你有一定的参考价值。

题目链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805447855292416

开散列的方法是我从别人博客学到的,也是第一次用,感觉挺好用的,下次遇见这样的题目就有思路了。

然后里面sync_with_stdio(false)和下面的那句话是为了加速输入输出的,这是c++兼容c输入输出的方式,但是在测试的时候,oj会报段错误,我测试了一下,只有这两句话还是会报错,之前我也用过这样的语句,没报错,这里是为什么呢?

代码如下:

 1 #include<iostream>
 2 #include<vector>
 3 #include<stdio.h>
 4 #include<fstream>
 5 #include<algorithm>
 6 #include<cstdlib>
 7 using namespace std;
 8 const int maxn = 26*26*26+10;
 9 int trans(char name[]){
10     int ret = 0;
11     for(int i = 0; i < 3; i++){
12         ret = ret*26+name[0]-A;
13     }
14     ret += name[3]-0;
15     return ret;
16 }
17 vector<int> v[maxn];
18 int main(){
19     //ios::sync_with_stdio(false);
20     //cin.tie(0);
21     int n,m,k,l;
22     int stem;
23     char name[5];
24     cin >> n >> m;
25     for(int i = 0; i < m; i++){
26         cin >> k >> l;
27         for(int j = 0; j < l; j++){
28             scanf("%s",name);
29 //            cin >> name;
30             stem = trans(name);
31             v[stem].push_back(k);
32 //            cout << stem << endl;
33         }
34     }
35     vector<int>::iterator it;
36     for(int i = 0; i < n; i++){
37         scanf("%s",name);
38 //        cin >> name;
39         stem = trans(name);
40         cout << name << " " << v[stem].size();
41         sort(v[stem].begin(),v[stem].end());
42         for(it = v[stem].begin(); it != v[stem].end(); it++){
43             cout << " " << *it;
44         }
45         cout << endl;
46     }
47     return 0;
48 }

 

以上是关于1039 Course List for Student的主要内容,如果未能解决你的问题,请参考以下文章