Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.17 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. struct Student {
  6.     string name;
  7.     string surName;
  8.     double mark;
  9. };
  10. int main() {
  11.     int n;
  12.     cin >> n;
  13.     Student arr[1000];
  14.     for (int i = 0; i < n; i++) {
  15.         cin >> arr[i].name;
  16.         cin >> arr[i].surName;
  17.         cin >> arr[i].mark;
  18.     }
  19.     string command;
  20.     cin >> command;
  21.     if (n == 0) {
  22.         cout << "-1";
  23.     }
  24.     if (command == "max") {
  25.         int first = 0;
  26.         for (int i = 0; i < n; i++) {
  27.             if (arr[i].mark > arr[first].mark) {
  28.                 first = i;
  29.             }
  30.         }
  31.         cout << arr[first].name << " " << arr[first].surName;
  32.     }
  33.     else if (command == "avg") {
  34.         bool a = false;
  35.         double sum = 0.0;
  36.         for (int i = 0; i < n; i++) {
  37.             sum += arr[i].mark;
  38.         }
  39.         int mid = sum / n;
  40.         for (int i = 0; i < n; i++) {
  41.             if (arr[i].mark > mid) {
  42.                 a = true;
  43.                 cout << arr[i].name << " " << arr[i].surName << endl;
  44.             }
  45.         }
  46.  
  47.         if (a == false) {
  48.             cout << "-1";
  49.         }
  50.     }
  51.     else {
  52.         bool a = false;
  53.         string name;
  54.         cin >> name;
  55.         for (int i = 0; i < n; i++) {
  56.             if (arr[i].name == name) {
  57.                 a = true;
  58.                 cout << arr[i].name << " " << arr[i].surName << endl;
  59.             }
  60.         }
  61.         if (a == false) {
  62.             cout << "-1";
  63.         }
  64.     }
  65.  
  66.  
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement