回文时间sdut2174

http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2174&cid=1174

第一种方法,用if else进行麻烦的判断。。。

 1 #include<stdio.h>
 2 #include<string.h>
 3 int main()
 4 {
 5     char ch[7] ;
 6     while(~scanf("%s",ch))
 7     {
 8         int a = 10*(ch[0]-'0')+(ch[1] - '0') ;
 9         int b = 10*(ch[1]-'0')+(ch[0] - '0') ;
10         int c = 10*(ch[3]-'0')+(ch[4] - '0') ;
11         int d = 10*(ch[4]-'0')+(ch[3] - '0') ;
12         if(a >= 6&&a <= 9)
13             printf("10:01\n");
14         else if(a >= 16&&a <= 19)
15             printf("20:02\n") ;
16         else
17         {
18             if(b > c)
19             {
20                 printf("%02d:%02d\n",a,b);
21             }
22             else
23             {
24                 if(a == 23)
25                     printf("00:00\n") ;
26                 else
27                 {
28                     int x = a+1;
29                     if(x >= 6 &&x <= 9 )
30                     {
31                         printf("10:01\n");
32                         continue;
33                     }
34                     else if(x >= 16&&x <= 19)
35                     {
36                         printf("20:02\n");
37                         continue;
38                     }
39                     else
40                     {
41                         printf("%02d:%02d\n",x,(x%10)*10+(x/10));
42                         continue;
43                     }
44                 }
45             }
46         }
47     }
48     return 0 ;
49 }
View Code

第二种方法,定义结构体,把所有的情况进行枚举

 1 #include<stdio.h>
 2 #define max 1000
 3 char s[30];
 4 struct node
 5 {
 6     int h;
 7     int m;
 8 } p[30];
 9 int main()
10 {
11     p[1].h=1;
12     p[1].m=10;
13     p[2].h=2;
14     p[2].m=20;
15     p[3].h=3;
16     p[3].m=30;
17     p[4].h=4;
18     p[4].m=40;
19     p[5].h=5;
20     p[5].m=50;
21     p[6].h=10;
22     p[6].m=1;
23     p[7].h=11;
24     p[7].m=11;
25     p[8].h=12;
26     p[8].m=21;
27     p[9].h=13;
28     p[9].m=31;
29     p[10].h=14;
30     p[10].m=41;
31     p[11].h=15;
32     p[11].m=51;
33     p[12].h=20;
34     p[12].m=2;
35     p[13].h=21;
36     p[13].m=12;
37     p[14].h=22;
38     p[14].m=22;
39     p[15].h = 23 ;
40     p[15].m = 32 ;
41     while(scanf("%s",s)!=EOF)
42     {
43         int hh=(s[0]-'0')*10+(s[1]-'0');
44         int mm=(s[3]-'0')*10+(s[4]-'0');
45         if(hh==23&&mm>=32)
46         {
47             printf("00:00\n");
48         }
49         else
50         {
51             for(int i=1;i<=15;i++)
52             {
53                 if(p[i].h==hh&&p[i].m>mm)
54                 {
55                     printf("%02d:%02d\n",p[i].h,p[i].m);
56                     break;
57                 }
58                 else if(p[i].h>hh)
59                 {
60                     printf("%02d:%02d\n",p[i].h,p[i].m);
61                     break;
62                 }
63             }
64         }
65     }
66     return 0;
67 }
View Code

第三种方法,利用for循环进行循环判断,注意终止条件

 1 #include<stdio.h>
 2 int main(void)
 3 {
 4     int h, m;
 5     while(~scanf("%d:%d", &h, &m))
 6     {
 7         for(m++ ; ; m++)
 8         {
 9             if(m == 60)
10             {
11                 m = 0;
12                 h++;
13                 if(h==24) h = 0;
14             }
15             if(h%10==m/10 && m%10==h/10)
16             {
17                 printf("%02d:%02d\n", h, m);
18                 break;
19             }
20         }
21     }
22     return 0;
23 }
View Code
原文地址:https://www.cnblogs.com/luyingfeng/p/3112884.html