24h購物| | PChome| 登入
2012-04-29 06:47:43| 人氣2,144| 回應0 | 上一篇 | 下一篇

[UVA][迴文] 11309 - Counting Chaos

推薦 0 收藏 0 轉貼0 訂閱站台

Problem C

COUNTING CHAOS

Wolfgang Puck's rival, Emeril Lagasse ("BAM!"), recently set the world culinary record in the category of smallest soufflé measuring in at a mere 2 cm! Wolfgang, not to be outdone, decided that he would set a culinary record of his own: the most symmetric marble cake in the world. This is clearly not an easy feat!

As we all know from Wolfgang's bestselling biography, he is a very superstitious chef. In his attempts to create the symmetric cake, he has vowed to remove the cake from the oven only at a palindromic time, i.e., a time that reads the same when read from left-to-right as right-to-left. Not including the current time, when is the next opportunity for Wolfgang to remove his cake?

Input

On the first line of the input you are given n, the number of attempts Wolfgang makes to make his symmetric cake. The following n lines contain a string formatted as "HH:MM" indicating the current time on a twenty-four hour clock. (So 0 ≤ HH ≤ 23 and 0 ≤ MM ≤ 59 and "00:00" follows "23:59")

Output

For each attempt, output a string indicating the next palindromic time (not including the current time) on a single line formatted as "hh:mm". When determining if HH:MM is palindromic, ignore all leading zeroes in HH. If HH is zero then ignore all leading zeroes in MM.

Sample Input

3
00:00
23:30
14:59

Output for the Sample Input

00:01
23:32
15:51

#include <stdio.h>
#include <string.h>

int main() {
    int t, x, y, n;
    int i, j;
    scanf("%d", &t);
    while(t--) {
        scanf("%d:%d", &x, &y);
        int time = x*60 + y;
        char str[10];
        do {
            time++;
            if(time >= 1440)    time = 0;
            x = time/60, y = time%60;
            sprintf(str, "%02d%02d", x, y);
            sscanf(str, "%d", &n);
            sprintf(str, "%d", n);
            int flag = 0;
            for(i = 0, j = strlen(str)-1; i < j; i++, j--)
                if(str[i] != str[j])
                    flag = 1;
            if(!flag) {
                sprintf(str, "%02d:%02d", x, y);
                puts(str);
                break;
            }
        } while(true);
    }
    return 0;
}

台長: Morris
人氣(2,144) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA] 297 - Quadtrees
此分類上一篇:[UVA][中國郵路問題] 10296 - Jogging Trails

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文