Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <Windows.h>
- #include <string>
- using namespace std;
- struct student_t
- {
- string surname;
- string faculty;
- size_t course_id;
- };
- struct pair_t
- {
- string faculty;
- size_t course_id;
- };
- int main()
- {
- SetConsoleOutputCP(1251);
- SetConsoleCP(1251);
- size_t size;
- size_t n_unique = 0;
- cin >> size;
- cin.ignore();
- student_t* students = new student_t[size];
- pair_t* unique_pairs = new pair_t[size];
- for (size_t i = 0; i < size; i++)
- {
- cout << endl << i + 1 << " student: " << endl;
- string tmp_str;
- size_t tmp_id;
- cout << "Enter surname = ";
- getline(cin, tmp_str);
- students[i].surname = tmp_str;
- cout << "Enter faculty = ";
- getline(cin, tmp_str);
- students[i].faculty = tmp_str;
- cout << "Enter course id = ";
- cin >> tmp_id;
- cin.ignore();
- students[i].course_id = tmp_id;
- bool is_unique = true;
- for (size_t j = 0; j < n_unique; j++)
- if (unique_pairs[j].course_id == tmp_id && unique_pairs[j].faculty == tmp_str)
- {
- is_unique = false;
- break;
- }
- if (is_unique)
- {
- unique_pairs[n_unique].faculty = tmp_str;
- unique_pairs[n_unique].course_id = tmp_id;
- n_unique++;
- }
- }
- for (size_t i = 0; i < n_unique; i++)
- {
- string max;
- for (size_t j = 0; j < size; j++)
- {
- if (students[j].faculty == unique_pairs[i].faculty && students[j].course_id == unique_pairs[i].course_id)
- if (students[j].surname.size() > max.size())
- max = students[j].surname;
- }
- cout << "The longest surname on faculty '" << unique_pairs[i].faculty << "' and course '" << unique_pairs[i].course_id << "' is " << max << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement