/*********************************************
This program reads trial data from a roach
experiment, reads a time from the user, and
tells the user where the roach was going at
that point in time.
**********************************************/
#include "point.h"
#include "hhmmss.h"
#include <string>
using namespace std;

/*********************************************
 ** PROTOTYPES & STRUCT DEFINITIONS
 *********************************************/
//--- A DATA READING FROM THE EXPERIMENT ----//
struct datum
{
  point position;
  hhmmss time;
};
void read(datum &D, istream &IN);

/*********************************************
 ** MAIN FUNCTION
 *********************************************/
int main()
{
  // Open file and read heading info
  int N;
  string s;
  ifstream IN("trial.txt");
  IN >> N >> s >> s;

  // Read and store data readings
  datum *A = new datum[N];
  for(int i = 0; i < N; i++)
    read(A[i],IN);

  // Get the query time from the user
  hhmmss T;
  cout << "Enter a time: ";
  read(T,cin);

  // Find the first sighting at or after given time
  int k = 0; 
  while (k < N && A[k].time < T)
    k++;
  
  // Write result
  if (k == 0)
  {
    cout << "This was before the first sighting at ";
    write(A[0].position,cout);
    cout << endl;
  }
  else if (k == N)
  {
    cout << "This was after the last sighting at ";
    write(A[N-1].position,cout);
    cout << endl;
  }
  else
  {
    cout << "The roach was somewhere between ";
    write(A[k-1].position,cout);
    cout << " and ";
    write(A[k].position,cout);    
    cout << endl;
  }

  return 0;
}

/*********************************************
 ** FUNCTION DEFINITIONS
 *********************************************/
void read(datum &D, istream &IN)
{
  char c;
  IN >> c;
  read(D.time,IN);
  IN >> c;
  read(D.position,IN);
  IN >> c;
}