Advertisement
Sanlover

Untitled

Dec 17th, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. #include <iostream>
  2. #include <Windows.h>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. struct student_t
  8. {
  9. string surname;
  10. string faculty;
  11. size_t course_id;
  12. };
  13.  
  14. struct pair_t
  15. {
  16. string faculty;
  17. size_t course_id;
  18. };
  19.  
  20. int main()
  21. {
  22. SetConsoleOutputCP(1251);
  23. SetConsoleCP(1251);
  24. size_t size;
  25. size_t n_unique = 0;
  26.  
  27. cin >> size;
  28. cin.ignore();
  29. student_t* students = new student_t[size];
  30. pair_t* unique_pairs = new pair_t[size];
  31.  
  32. for (size_t i = 0; i < size; i++)
  33. {
  34. cout << endl << i + 1 << " student: " << endl;
  35. string tmp_str;
  36. size_t tmp_id;
  37. cout << "Enter surname = ";
  38. getline(cin, tmp_str);
  39. students[i].surname = tmp_str;
  40.  
  41. cout << "Enter faculty = ";
  42. getline(cin, tmp_str);
  43. students[i].faculty = tmp_str;
  44.  
  45. cout << "Enter course id = ";
  46. cin >> tmp_id;
  47. cin.ignore();
  48. students[i].course_id = tmp_id;
  49.  
  50. bool is_unique = true;
  51. for (size_t j = 0; j < n_unique; j++)
  52. if (unique_pairs[j].course_id == tmp_id && unique_pairs[j].faculty == tmp_str)
  53. {
  54. is_unique = false;
  55. break;
  56. }
  57. if (is_unique)
  58. {
  59. unique_pairs[n_unique].faculty = tmp_str;
  60. unique_pairs[n_unique].course_id = tmp_id;
  61. n_unique++;
  62. }
  63. }
  64.  
  65. for (size_t i = 0; i < n_unique; i++)
  66. {
  67. string max;
  68. for (size_t j = 0; j < size; j++)
  69. {
  70. if (students[j].faculty == unique_pairs[i].faculty && students[j].course_id == unique_pairs[i].course_id)
  71. if (students[j].surname.size() > max.size())
  72. max = students[j].surname;
  73. }
  74. cout << "The longest surname on faculty '" << unique_pairs[i].faculty << "' and course '" << unique_pairs[i].course_id << "' is " << max << endl;
  75. }
  76. return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement