因为只有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;
}


被折叠的 条评论
为什么被折叠?



