lundi 1 février 2021

find the latest time using class [duplicate]

How can I solve this exercise in an easier way? I have a class. There are three objects for an hour, minute, and second. At first, I'm giving my count and then my time. So I need to find the maximum hour, minute, and second.

    #include <iostream>

    class TimeS {
    private:
        int hour;
        int minute;
        int second;
    public:
        TimeS(int h = 0, int m = 0, int s = 0)
            :hour(h), minute(m),second(s) {
        }
        int get_hour() {
            return hour;
        }
        int get_minute() {
            return minute;
        }
        int get_second() {
            return second;
        }

        int checker(int ch) {
            int value = INT_MIN;
            if (ch > value) {
                value = ch;
            }
            return ch;
            }

    };
    int main() {
        int N;
        int count = 0;
        std::cin >> N;
        TimeS* t = new TimeS[N];
        for (int i = 0; i < N; ++i) {
            int h;
            int m;
            int s;
            std::cin >> h >> m >> s;
            t[i] = TimeS(h, m, s);
        }
        int hr;
        int mt;
        int sc;
        std::cin >> hr >> mt >> sc;
        for (int i = 0; i < N; ++i) {
            if () {//I need to write here something
                    std::cout << t[i].get_hour()<<t[i].get_minute()<<t[i].get_second()<< std::endl;
                    count++;
                }
            }
        if (count == 0) {
            std::cout << "Unreachable city!" << std::endl;
            }
        return 0;
        }

for example I want to input

    5
    12 59 14
    15 16 23
    20 58 58
    23 29 30
    23 29 59

And get

23 29 59

I'm a beginner. So in this part already I can't continue coding.

Aucun commentaire:

Enregistrer un commentaire