Advertisement
Guest User

Untitled

a guest
Dec 14th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.80 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include "stdio.h"
  4. #include "stdlib.h"
  5.  
  6. using namespace std;
  7. struct Time
  8. {
  9.     int hTens, hOnes, mTens, mOnes;
  10.     void printTime()
  11.     {
  12.         cout<<hTens<<hOnes<<':'<<mTens<<mOnes<<endl;
  13.     }
  14. };
  15. struct FlightTimes
  16. {
  17.     Time flyOutTime,flyInTime;
  18. };
  19. struct Flight
  20. {
  21.     //FlightTimes times;
  22.     int from, to;
  23.     FlightTimes * flightArr1;
  24.     int flightCount;
  25.     void makeFlightArr()
  26.     {
  27.         cout<<"Makes array with "<<flightCount<<endl;
  28.         flightArr1 = new FlightTimes[flightCount]; // Man vajag šajā masīvā ielikt to temp
  29.         cout<<sizeof(flightArr1)<<endl;//Man viņš ir ar tipu FlightTimes. Tāds pats kāds temp
  30.     }
  31. };
  32. struct FlightCalculator
  33. {
  34.     Time startTime;
  35.     int flightAmount, startAirport, endAirport, notLast;
  36.     char str[100];
  37.     FlightTimes *FlightTimes, temp;//<---- temp
  38.     char trash1,trash2,trash3;
  39.     Flight * flightArr;
  40.     int flightNo = 0;
  41.     void letsGo()
  42.     {
  43.         FILE * nice;
  44.         nice = fopen("lidosta.in", "r");
  45.         getMainInfo(nice);
  46.         while(true)
  47.         {
  48.             Flight * current = new Flight(); // Nodefinējas current
  49.             if(fgets(str, 100, nice)==NULL) break;
  50.             sscanf(str,"%u",&notLast);
  51.             if(!notLast) break;
  52.             char restOfTimes[100] = {NULL};
  53.             sscanf(str,"%u %u %u %[^\t\n]",&current->from,&current->to,&current->flightCount,restOfTimes);
  54.             cout<<current->flightCount<<endl;
  55.             current->makeFlightArr();
  56.             int i = current->flightCount;
  57.             while(i)
  58.             {
  59.                 restOfTimes[0]==NULL;
  60.  
  61.                 //break;
  62.                 // sscanf(str,"%u %u %u %[^\t\n]",&current->from,&current->to,&current->flightCount,restOfTimes);
  63.                 sscanf(restOfTimes,"%1u %1u %1c %1u %1u %1c %1u %1u %1c %1u %1u %[^\t\n] ",
  64.                        &temp.flyOutTime.hTens,
  65.                        &temp.flyOutTime.hOnes,
  66.                        &trash1,
  67.                        &temp.flyOutTime.mTens,
  68.                        &temp.flyOutTime.mOnes,
  69.                        &trash2,
  70.                        &temp.flyInTime.hTens,
  71.                        &temp.flyInTime.hOnes,
  72.                        &trash3,
  73.                        &temp.flyInTime.mTens,
  74.                        &temp.flyInTime.mOnes,
  75.                        &restOfTimes);
  76. cout<<temp.flyOutTime.hTens<<temp.flyOutTime.hOnes<<':'<<temp.flyOutTime.mTens<<temp.flyOutTime.mOnes<<endl;
  77. //cout<<restOfTimes<<endl;
  78.                         current->flightArr1[i] = temp; // Te notiek crash
  79.                        cout<<sizeof(current->flightArr1)<<endl;//[i] = temp;
  80.                        //temp.flyInTime.printTime();
  81.                      //  temp.flyOutTime.printTime();
  82.                        i--;
  83.                       // if(i==3)
  84.                       // break;
  85.             }
  86. cout<<endl;
  87.             //cout<<strlen(str)<<endl;
  88.             if(restOfTimes[0]!=NULL)
  89.             {
  90.                 //cout<<restOfTimes<<" test"<<endl;
  91.             }
  92.  
  93.         }
  94.         fclose(nice);
  95.     }
  96.     void makeFlightArr(int i)
  97.     {
  98.         flightArr = new Flight[i];
  99.     }
  100.     void getMainInfo(FILE * nice)
  101.     {
  102.         fgets(str, 100, nice);
  103.         sscanf(str,"%1u",&flightAmount);
  104.         makeFlightArr(flightAmount);
  105.         cout<<flightAmount<<endl;
  106.         fgets(str, 100, nice);
  107.         sscanf(str,"%1u %1u",&startAirport, &endAirport);
  108.         cout<<startAirport<<' '<<endAirport<<endl;
  109.         fgets(str, 100, nice);
  110.         sscanf(str,"%1u %1u %1c %1u %1u",&startTime.hTens,&startTime.hOnes,&trash1,&startTime.mTens, &startTime.mOnes);
  111.         startTime.printTime();
  112.     }
  113. };
  114.  
  115.  
  116.  
  117. int main()
  118. {
  119.     FlightCalculator flight;
  120.     flight.letsGo();
  121.     //cout<<"Hello world";
  122.     return 0;
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement