Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.21 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std; //C
  5.  
  6. typedef struct GEP{
  7. int h;
  8. int m;
  9. int s;
  10. int t; //eltelt ido
  11. char C; //városnév
  12. int ido; // mp atvaltva h p mp
  13. }GEP;
  14.  
  15.  
  16. int main()
  17. {
  18.     fstream f;
  19.     int db;
  20.     f.open("forgalom.txt",ios::in);
  21.     f>>db;
  22.     GEP t[db];
  23.     int i=0;
  24.     while(i<db){
  25.         f>>t[i].h;
  26.         f>>t[i].m;
  27.         f>>t[i].s;
  28.         f>>t[i].t;
  29.         f>>t[i].C;
  30.         t[i].ido=t[i].h*3600+t[i].m*60+t[i].s;
  31.         i++;
  32.     }
  33.   //  cout << t[db-1].s <<" "<< t[db-1].t<<" "<<t[db-1].C<< endl;
  34.     f.close();
  35.     cout<<"2.feladat"<<endl;
  36.     cout<<"Kerek egy szamot:"<<endl;
  37.     int n;
  38.     cin>>n;
  39.     if(db<n) cout<<"Ennyi kocsi nem is vot"<<endl;
  40.     else if(t[n-1].C=='F') cout<< " A varos fele haladt"<<endl;
  41.          else cout<< " F varos fele haladt"<<endl;
  42.     cout<<"3.feladat"<<endl;
  43.     i=db-1;//végére előre
  44.     int j;
  45.     while(i>=0){
  46.         if(t[i].C=='A'){
  47.            j=i-1;
  48.            while(j>=0){
  49.                       if(t[j].C=='A')  {
  50.                         cout<<t[i].ido-t[j].ido<<endl;
  51.                         break;
  52.                       }
  53.            j--;
  54.  
  55.            }
  56.           break;
  57.         }
  58.         i--;
  59.     }
  60.     cout<<"4.feladat"<<endl;
  61.     i=1; //elsőt nem nézzük :(
  62.     int aktA=0;
  63.     int aktF=0;
  64.     if(t[0].C=='A') aktA++;
  65.             else aktF++;// de igy igen
  66.  
  67.     while(i<db-1){
  68.         if(t[i].h==t[i-1].h){
  69.             if(t[i].C=='A') aktA++;
  70.             else aktF++;
  71.         }
  72.         else{
  73.             cout<<t[i-1].h<<" A : "<<aktA<<" F : "<<aktF<<endl;
  74.             aktA=0;
  75.             aktF=0;
  76.             if(t[i].C=='A') aktA++;
  77.             else aktF++;
  78.         }
  79.  
  80.  
  81.  
  82.         i++;
  83.     }
  84.     cout<<t[db-1].h<<" A : "<<aktA<<" F : "<<aktF<<endl;
  85.  
  86.     cout<<"5.feladat."<<endl;
  87.     i=0;
  88.     j=0;
  89.     GEP seged;
  90.     while(i<db-1){
  91.         j=i+1;
  92.         while(j<db-1){
  93.             //csere
  94.             if(t[i].t>t[j].t){
  95.                 seged=t[i];
  96.                 t[i]=t[j];
  97.                 t[j]=seged;
  98.             }
  99.         j++;
  100.          }
  101.  
  102.      i++;
  103.     }
  104.  
  105. i=0;
  106. while(i<10){
  107.     cout << t[i].t<<"ez meg nem sebesseg"<<endl;
  108.     i++;
  109. }
  110.  
  111.  
  112.     return 0;
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement