Monday, June 9, 2014

Topcoder High School SRM 8 250 pt - Level one - Fussy Sleeper solution

Topcoder High School SRM 250 pt - Level one - Fussy Sleeper statement: http://community.topcoder.com/stat?c=problem_statement&pm=6259&rd=10060

Topcoder High School SRM 250 pt - Level one - Fussy Sleeper editorial: http://community.topcoder.com/tc?module=Static&d1=hs&d2=match_editorials&d3=hs_srm8

Topcoder High School SRM 250 pt - Level one - Fussy Sleeper solution: 

#include <iostream>
#include <vector>
using namespace std;

class FussySleeper {
    public: vector <int> nextTime(vector <int> currentTime, int elephants) {
        int a, b, c;
        a = currentTime[0] * 100 + currentTime[1];
        b = currentTime[0], c = currentTime[1];
        do {
            currentTime[1]++;
            if(currentTime[1] == 60) currentTime[0]++, currentTime[1] = 0;
            if(currentTime[0] == 24) currentTime[0] = 0;
            a = currentTime[0] * 100 + currentTime[1];
            if(b == currentTime[0] && c == currentTime[1]) {
                if(a % elephants == 0) break;
                else {
                    currentTime[0] = 0;
                    currentTime[1] = 0;
                    break;
                } 
            }
        } while(a % elephants != 0); 
        return currentTime;
    }
};

No comments:

Post a Comment