Advertisement
Guest User

10. Hospital

a guest
Feb 17th, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct Hospital {
  6.   char name[100];
  7.   char diagnose[100];
  8.   int days;
  9. };
  10.  
  11. int main()
  12. {
  13.     Hospital patients[100] = {};
  14.     int n;
  15.     cin>>n;
  16.     for(int i = 0; i < n; i++)
  17.     {
  18.         Hospital patient;
  19.         cin>>patient.name>>patient.diagnose>>patient.days;
  20.         patients[i] = patient;
  21.     }
  22.  
  23.     for(int i = 0; i < n; i++)
  24.     {
  25.         cout<<patients[i].name<<endl;
  26.     }
  27.  
  28.     int longestIndex = 0;
  29.     for(int i = 0; i < n; i++)
  30.     {
  31.         if(patients[i].days > patients[longestIndex].days)
  32.         {
  33.             longestIndex = i;
  34.         }
  35.     }
  36.  
  37.     Hospital longestPatient = patients[longestIndex];
  38.     cout<<longestPatient.name<<" "<<longestPatient.diagnose<<" "<<longestPatient.days<<endl;
  39.  
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement