CF:108A. Palindromic Times

来源:互联网 发布:cda数据分析师有什么用 编辑:程序博客网 时间:2024/05/17 22:21

因为只有24个小时,所以这道题用了“傻瓜式”的方法,如果数再大一点的话,就得另想法子了。这道题要比较的次数不较多所以用string类是再好不过的了。

#include<iostream>#include<string>using namespace std;int main(){    string t;    while(cin>>t){        string h=t.substr(0,2);        string m=t.substr(3,2);        if(h!="05"&&h!="06"&&h!="07"&&h!="08"&&h!="09"){            if(h!="15"&&h!="16"&&h!="17"&&h!="18"&&h!="19"){                if(h=="23"&&m>="32")                    cout<<"00:00"<<'\n';                else{                    string s="00";                    s[0]=h[1];                    s[1]=h[0];                    if(m>=s){                        h[1]=h[1]+1;                        s[0]=h[1];                    }                    cout<<h<<":"<<s<<'\n';                }            }            else{                if(h=="15"&&m<"51")                    cout<<"15:51"<<'\n';                else                    cout<<"20:02"<<'\n';            }        }        else{            if(h=="05"&&m<"50")                cout<<"05:50"<<'\n';            else                cout<<"10:01"<<'\n';        }    }    return 0;}