Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -----Main.cpp------
- #pragma once
- #include <iostream>
- #include <string>
- #include <vector>
- #include "Timespan.h"
- using namespace std;
- int main()
- {
- int n;
- cin >> n;
- vector<Timespan> times;
- for(int i = 0; i < n; i++)
- {
- int d, m, h, s;
- cin >> d >> h >> m >> s;
- times.push_back(Timespan(d, h, m, s));
- }
- for(int i = 0; i < n; i++)
- {
- for(int j = i+1; j < n; j++)
- {
- if(times[i] > times[j])
- {
- Timespan tmp = times[i];
- times[i] = times[j];
- times[j] = tmp;
- }
- }
- }
- for(int i = 0; i < n; i++)
- cout << times[i] << endl;
- return 0;
- }
- -----Timespan.cpp------
- #include "Timespan.h"
- Timespan::Timespan()
- {
- }
- Timespan::Timespan(int days, int hours, int minutes, int seconds)
- {
- this->days = days;
- this->hours = hours;
- this->minutes = minutes;
- this->seconds = seconds;
- }
- Timespan::~Timespan()
- {
- }
- bool Timespan::operator >(const Timespan& other)
- {
- if (days > other.days) return true;
- else if (days == other.days && hours > other.hours) return true;
- else if (days == other.days && hours == other.hours && minutes > other.minutes) return true;
- else if (days == other.days && hours == other.hours && minutes == other.minutes && seconds > other.seconds) return true;
- else return false;
- }
- ostream& operator <<(ostream& izlaz, Timespan other)
- {
- int ukupno, dani, sati, minute, sekunde;
- dani = other.days * 86400;
- sati = other.hours * 3600;
- minute = other.minutes * 60;
- ukupno = dani + sati + minute + other.seconds;
- dani = ukupno / 60 / 60 / 24;
- sati = (ukupno / 60 / 60) % 24;
- minute = (ukupno / 60) % 60;
- sekunde = ukupno % 60;
- if (dani > 0) izlaz << dani << "d ";
- if (sati > 0) izlaz << sati << "h ";
- if (minute > 0) izlaz << minute << "min ";
- if (sekunde > 0) izlaz << sekunde << "sec";
- return izlaz;
- }
- -----Timespan.h---------
- #pragma once
- #include <iostream>
- #include <string>
- #include <vector>
- using namespace std;
- class Timespan
- {
- private:
- int days, hours, minutes, seconds;
- public:
- Timespan();
- Timespan(int days, int hours, int minutes, int seconds);
- ~Timespan();
- bool operator >(const Timespan& other);
- friend ostream& operator <<(ostream& izlaz, Timespan other);
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement