ostapdontstop

Ignat

Jun 24th, 2018
120
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <cstring>
  3. #include <windows.h>
  4. using namespace std;
  5.  
  6. struct sportsman {
  7.     char fam[80], name[80], otch[80], sport[80];
  8.     int year;
  9. };
  10. ostream& operator << (ostream& cout, const sportsman& a) {
  11.     cout<< a.fam << ' '  << a.name[0] << ' '  << a.otch[0] << endl;
  12. }
  13. sportsman* search (sportsman *a, sportsman *last, int year) {
  14.     while (a!=last) {
  15.         if(a->year == year) return a;
  16.         a++;
  17.     }
  18.     return NULL;
  19. }
  20. int main() {
  21.     SetConsoleCP (1251);
  22.     SetConsoleOutputCP (1251);
  23.     sportsman a[] = {
  24.         {"Наливайко", "Игорь", "Андреевич", "футбол", 1999},
  25.         {"Веркеенко", "Евгений", "Владимирович", "бег", 2000},
  26.         {"Ли", "Артем", "Григорьевич", "плаванье", 1999},
  27.         {"Салохян", "Григорий", "Александрович", "футбол", 1999},
  28.         {"Резяпкин", "Сергей", "Борисович", "плаванье", 1999},
  29.     }; int n = 5;
  30.     int min_year = a[0].year;
  31.     for (int i = 0; i < n; i++)
  32.         if (a[i].year < min_year) min_year = a[i].year;
  33.     sportsman *p = search(a,a+n, min_year);
  34.     while (p) {
  35.         cout << *p;
  36.         p = search(p+1,a+n, min_year);
  37.     }
  38.  
  39. }
RAW Paste Data