PAT1039

卡两样东西,一个是string的map,另一个是cin,cout

谢谢PAT让我感受到了OI的风采

 1 #include <iostream>
 2 #include <vector>
 3 #include <string>
 4 #include <fstream>
 5 #include <map>
 6 #include <algorithm>
 7
 8 using namespace std;
 9
10 //#define OJ
11
12 #ifdef OJ
13 #define fin cin
14 #endif
15
16 int hash_str(const char *str){
17     return (str[0] - ‘A‘) * 26 * 26 * 10 + (str[1] - ‘A‘) * 26 * 10 + (str[2] - ‘A‘) * 10 + (str[3] - ‘0‘);
18 }
19
20 vector<int> student_course[26 * 26 * 26 * 10];
21
22 int main(){
23 #ifndef OJ
24     ifstream fin("in.data");
25 #endif
26
27     ios::sync_with_stdio(NULL);
28
29     int N, K;
30     fin >> N >> K;
31
32     char name[5];
33
34     for (int i = 0; i < K; i++){
35         int idx, num;
36         fin >> idx >> num;
37
38         for (int j = 0; j < num; j++){
39             fin >> name;
40             student_course[hash_str(name)].push_back(idx);
41         }
42     }
43
44     for (int i = 0; i < N; i++){
45         fin >> name;
46
47         vector<int> &course_idx = student_course[hash_str(name)];
48         sort(course_idx.begin(), course_idx.end());
49
50         printf("%s %d", name, course_idx.size());
51         for (int j = 0; j < course_idx.size(); j++){
52             printf(" %d", course_idx[j]);
53         }
54
55         printf("\n");
56     }
57
58     return 0;
59 }
时间: 2024-11-10 00:10:52

PAT1039的相关文章

PAT1039. Course List for Student (25)

水题,但是oj有毒,内存用了1/4,没炸内存,vector也开的够大,莫名给我个段错误,好烦 不能存学生的名字,存了,最后一组测试就给一个段错误,烦 #include<bits/stdc++.h> using namespace std; const int maxn=180000; vector<short> v[maxn]; char s[10]; int convert(char c){ if(isdigit(c))return c-'0'; return c-'A'+10;

浙大pat1039 Course List for Student(25 分)

1039 Course List for Student(25 分) Zhejiang University has 40000 students and provides 2500 courses. Now given the student name lists of all the courses, you are supposed to output the registered course list for each student who comes for a query. In

PAT1047: Student List for Course

1047. Student List for Course (25) 时间限制 400 ms 内存限制 64000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Zhejiang University has 40000 students and provides 2500 courses. Now given the registered course list of each student, you are supposed to output