problemscpp
A collection of my answers to algorithm problems in c++.
| 函数
pat::b::b1095 命名空间参考

1095 解码PAT准考证 更多...

struct  p_stu_comp
 
struct  room
 
struct  room_cnt_comp
 
struct  student
 

函数

int main (istream &cin, ostream &cout)
 
 TEST (b1095, case1)
 

详细描述

1095 解码PAT准考证

函数说明

◆ main()

int pat::b::b1095::main ( istream &  cin,
ostream &  cout 
)

在文件 pat.cpp3327 行定义.

3327 {
3328 int n;
3329 int m;
3330 cin >> n >> m;
3331 unordered_map<string, room> rooms;
3332 unordered_map<char, unordered_set<student *>> levels;
3333 unordered_map<string, unordered_map<string, int>> dates;
3334 for(int i = 0; i < n; i++) {
3335 auto *stu = new student();
3336 cin >> stu->id >> stu->grade;
3337 stu->level = stu->id[0];
3338 stu->room = stu->id.substr(1, 3);
3339 stu->date = stu->id.substr(4, 6);
3340 rooms[stu->room].sum += stu->grade;
3341 rooms[stu->room].count++;
3342 levels[stu->level].insert(stu);
3343 dates[stu->date][stu->room]++;
3344 }
3345 for(int i = 0; i < m; i++) {
3346 int typ;
3347 cin >> typ;
3348 cout << "Case " << i + 1 << ": " << typ << ' ';
3349 if(typ == 1) {
3350 char l;
3351 cin >> l;
3352 cout << l << endl;
3353 if(static_cast<unsigned int>(levels.contains(l)) != 0U) {
3354 vector<student *> vec;
3355 for(auto *const pstu: levels[l]) {
3356 vec.emplace_back(pstu);
3357 }
3358 sort(vec.begin(), vec.end(), p_stu_comp());
3359 for(auto *stu: vec) {
3360 cout << stu->id << ' ' << stu->grade << endl;
3361 }
3362 } else {
3363 cout << "NA" << endl;
3364 }
3365 } else if(typ == 2) {
3366 string room_id;
3367 cin >> room_id;
3368 cout << room_id << endl;
3369 if(static_cast<unsigned int>(rooms.contains(room_id)) != 0U) {
3370 cout << rooms[room_id].count << ' ' << rooms[room_id].sum << endl;
3371 } else {
3372 cout << "NA" << endl;
3373 }
3374 } else if(typ == 3) {
3375 string date;
3376 cin >> date;
3377 cout << date << endl;
3378 if(dates[date].empty()) {
3379 cout << "NA" << endl;
3380 continue;
3381 }
3382 vector<pair<string, int>> vec;
3383 for(const auto &room_cnt: dates[date]) {
3384 vec.emplace_back(room_cnt);
3385 }
3386 sort(vec.begin(), vec.end(), room_cnt_comp());
3387 for(const auto &[id, cnt]: vec) {
3388 cout << id << ' ' << cnt << endl;
3389 }
3390 } else {
3391 string op;
3392 cout << op << endl;
3393 cout << "NA" << endl;
3394 }
3395 }
3396 return 0;
3397 }
struct acwing::acwing3378::student student
int vec[100010]
Definition: pat.cpp:5095

引用了 pat::a::a7_2::vec.

被这些函数引用 TEST().

◆ TEST()

pat::b::b1095::TEST ( b1095  ,
case1   
)

在文件 pat_test.cpp1645 行定义.

1645 {
1646 istringstream in("8 4\n"
1647 "B123180908127 99\n"
1648 "B102180908003 86\n"
1649 "A112180318002 98\n"
1650 "T107150310127 62\n"
1651 "A107180908108 100\n"
1652 "T123180908010 78\n"
1653 "B112160918035 88\n"
1654 "A107180908021 98\n"
1655 "1 A\n"
1656 "2 107\n"
1657 "3 180908\n"
1658 "2 999");
1659 auto out = ostringstream();
1660 main(in, out);
1661 const auto ans = out.str();
1662 ASSERT_EQ("Case 1: 1 A\n"
1663 "A107180908108 100\n"
1664 "A107180908021 98\n"
1665 "A112180318002 98\n"
1666 "Case 2: 2 107\n"
1667 "3 260\n"
1668 "Case 3: 3 180908\n"
1669 "107 2\n"
1670 "123 2\n"
1671 "102 1\n"
1672 "Case 4: 2 999\n"
1673 "NA\n",
1674 out.str());
1675 }
int main(int argc, char **argv)
Definition: main.cpp:5

引用了 main().