Advertisement
Derga

Untitled

May 8th, 2023
614
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.44 KB | None | 0 0
  1. #include <fstream>
  2. #include <iostream>
  3. #include <string>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. struct ExamData {
  9.     int group_number;
  10.     int day;
  11.     int month;
  12.     int year;
  13.     int hours;
  14.     int minutes;
  15.     int class_number;
  16.     string subject;
  17.     string teacher_name;
  18. };
  19.  
  20. struct Date {
  21.     int day_, month_, year_;
  22.     Date(int day, int month, int year) :
  23.         day_(day)
  24.         , month_(month)
  25.         , year_(year)
  26.     {}
  27. };
  28.  
  29. ifstream& operator>> (ifstream& ifs, ExamData& exam) {
  30.     ifs >> exam.group_number >> exam.day >> exam.month >> exam.year
  31.         >> exam.hours >> exam.minutes >> exam.class_number
  32.         >> exam.subject >> exam.teacher_name;
  33.     return ifs;
  34. }
  35.  
  36. int main() {
  37.     vector<ExamData> exams_data;
  38.    
  39.     ifstream ifs("data.txt");
  40.     if (ifs.is_open()) {
  41.         while (!ifs.eof()) {
  42.             ExamData exam_data;
  43.             ifs >> exam_data;
  44.             exams_data.push_back(exam_data);
  45.         }
  46.     }
  47.  
  48.     string teacher_name;
  49.     cin >> teacher_name;
  50.  
  51.     vector<Date> dates;
  52.     for (const auto& exam_date : exams_data) {
  53.         if (exam_date.teacher_name == teacher_name) {
  54.             dates.push_back({exam_date.day, exam_date.month, exam_date.year });
  55.         }
  56.     }
  57.  
  58.     cout << dates.size() << '\n';
  59.     for (const auto& date : dates) {
  60.         cout << date.day_ << ' ' << date.month_ << ' ' << date.year_ << '\n';
  61.     }
  62.  
  63.     ifs.close();
  64.     return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement