I have to save into an array the hour format, example: 2:00AM, 3:45PM, 1:45AM, 12:56PM, etc., and next sort by the earliest hour, example: 1:45AM, 2:00AM, 12:56PM, 3:45PM. I only made the sort by the number but I don't really know how to sort by the "AM" or "PM" format.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
int cont = 0;
int num;
cout << "Introduce length of array: " << endl;
cin >> num;
string ar[num];
string hour;
cout << "Introduce hour (hh:mm AM or PM) example: 02:11PM" << endl;
for(int i = 0; i < num; i++)
{
cin >> hour;
ar[i] = hour;
}
sort(ar, ar + num);
cout << cont << endl;
for(int i = 0; i < num; i++)
{
cout << ar[i] << endl;
}
}
Aucun commentaire:
Enregistrer un commentaire