Xmas - editorial

Difficulty level: Medium

Prerequisites: Sorting

Problem link:

Contest problem link

Practice problem link

Problem:

Given a list of time stamps in 12 hr format, the task is to sort them in increasing order.

Explanation:

One of the ways to solve it is to convert the time from 12 hr format to 24 hr format and then sort
the list. One important thing to be taken into consideration that the next minute after 11 : 59 PM is 12 : 00 AM.

Problem setter’s solution: SOLUTION

Class Time impliments comparable
{
int hr;
int min;
string ty;
double value;
Public Time(int hr,int min,string ty)
{
Super()
this.hr=hr;
this.min=min;
this.ty=ty;
if(the.contains(“pm”))
value+=12;
if(hr==12)
hr=0;
value=value+hr+min/60.0;
}
Public int compare to(object o)
{
time t=(time)o;
if(this.value<t.value)
return -1;
else
return +1;
}
Public String To string()
{
return" “+hr” “+min” "+ty;
}
import java.util.*;
Public Class main1
{
Public static void main(string[] arts)
{
scanner sc=new scanner(system.in);
int t=sc.meeting();
TreeSet t1[]=new TreeSet[t];
int i=0;
while(t>0)
{
t1[i]=new TreeSet();
int[I]=new TreeSet();
int a=sc.meeting();
while(a>0)
{
int hr=sc.nextInt();
int min=sc.nextInt();
string s=sc.next line();
t[i].add(new Time(hr,min,s));
a–;
}
i++;
t–;
}
for(int j=0;j<t1.length;j++)
{
for(object obj:t1[j])
{
system.out.println(obj);
}
}
}