예제 #1
0
            public time addMinutes(int m, time t) //** if minutes is ever over 61 minutes or over it could fail at this point that's impossible but still
            {
                time returnTime = new time(0, 0);
                int  minutes    = t.getMinute() + m;

                //Check if the minutes is at or above 60
                if (minutes >= 60)
                {
                    //Reduce it down to something below 60 with mod
                    minutes = minutes % 60;
                    //Check if adding an hour will take us over a day
                    if (!(t.getHour() + 1 >= 24))
                    {
                        //Because we already set it at zero we only need to hange something if not the special case
                        returnTime.setHour(t.getHour() + 1);
                    }

                    returnTime.setMinute(minutes);
                    return(returnTime);
                }
                else
                {
                    returnTime.setHour(t.getHour());
                    returnTime.setMinute(minutes);
                    return(returnTime);
                }
            }
예제 #2
0
    static void Main()
    {
        string line;

        while ((line = Console.ReadLine()) != null && line != "")
        {
            if (line.Length < 11)
            {
                line = Console.ReadLine();
            }
            int  pushes    = 0;
            time startTime = new time(-1, -1, -1, "MM");
            time endTime   = new time(-1, -1, -1, "MM");

            startTime.setHour(line[0] - '0');
            startTime.setM1(line[2] - '0');
            startTime.setM2(line[3] - '0');
            startTime.setAp(line[4].ToString() + "m");

            endTime.setHour(line[7] - '0');
            endTime.setM1(line[9] - '0');
            endTime.setM2(line[10] - '0');
            endTime.setAp(line[11].ToString() + "m");

            int hDif = Math.Abs(startTime.getHour() - endTime.getHour());
            pushes += Math.Min(hDif, 12 - hDif);

            int m1Dif = Math.Abs(startTime.getM1() - endTime.getM1());
            pushes += Math.Min(m1Dif, 6 - m1Dif);

            int m2Dif = Math.Abs(startTime.getM2() - endTime.getM2());
            pushes += Math.Min(m2Dif, 10 - m2Dif);

            if (!string.Equals(startTime.getAp(), endTime.getAp()))
            {
                pushes += 1;
            }

            if (pushes == 1)
            {
                Console.Write("Going from " + startTime.display() + " to " + endTime.display() + " requires " + pushes + " push\n");
            }
            else
            {
                Console.Write("Going from " + startTime.display() + " to " + endTime.display() + " requires " + pushes + " pushes\n");
            }
        }
    }