Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std; //C
- typedef struct GEP{
- int h;
- int m;
- int s;
- int t; //eltelt ido
- char C; //városnév
- int ido; // mp atvaltva h p mp
- }GEP;
- int main()
- {
- fstream f;
- int db;
- f.open("forgalom.txt",ios::in);
- f>>db;
- GEP t[db];
- int i=0;
- while(i<db){
- f>>t[i].h;
- f>>t[i].m;
- f>>t[i].s;
- f>>t[i].t;
- f>>t[i].C;
- t[i].ido=t[i].h*3600+t[i].m*60+t[i].s;
- i++;
- }
- // cout << t[db-1].s <<" "<< t[db-1].t<<" "<<t[db-1].C<< endl;
- f.close();
- cout<<"2.feladat"<<endl;
- cout<<"Kerek egy szamot:"<<endl;
- int n;
- cin>>n;
- if(db<n) cout<<"Ennyi kocsi nem is vot"<<endl;
- else if(t[n-1].C=='F') cout<< " A varos fele haladt"<<endl;
- else cout<< " F varos fele haladt"<<endl;
- cout<<"3.feladat"<<endl;
- i=db-1;//végére előre
- int j;
- while(i>=0){
- if(t[i].C=='A'){
- j=i-1;
- while(j>=0){
- if(t[j].C=='A') {
- cout<<t[i].ido-t[j].ido<<endl;
- break;
- }
- j--;
- }
- break;
- }
- i--;
- }
- cout<<"4.feladat"<<endl;
- i=1; //elsőt nem nézzük :(
- int aktA=0;
- int aktF=0;
- if(t[0].C=='A') aktA++;
- else aktF++;// de igy igen
- while(i<db-1){
- if(t[i].h==t[i-1].h){
- if(t[i].C=='A') aktA++;
- else aktF++;
- }
- else{
- cout<<t[i-1].h<<" A : "<<aktA<<" F : "<<aktF<<endl;
- aktA=0;
- aktF=0;
- if(t[i].C=='A') aktA++;
- else aktF++;
- }
- i++;
- }
- cout<<t[db-1].h<<" A : "<<aktA<<" F : "<<aktF<<endl;
- cout<<"5.feladat."<<endl;
- i=0;
- j=0;
- GEP seged;
- while(i<db-1){
- j=i+1;
- while(j<db-1){
- //csere
- if(t[i].t>t[j].t){
- seged=t[i];
- t[i]=t[j];
- t[j]=seged;
- }
- j++;
- }
- i++;
- }
- i=0;
- while(i<10){
- cout << t[i].t<<"ez meg nem sebesseg"<<endl;
- i++;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement