坏掉的手表

坏掉的手表

时间限制: 1 Sec  内存限制: 128 MB

题目描述

有个手表坏了,时间为HH:MM,你要把这个不合法的时间变为合法,请求出最少要动几位

输入

第一行表示手表时间是什么制式
第二行HH:MM表示手表当前时间

输出

一个整数表示答案

样例输入

12
17:30

样例输出

1

题解

  没有手表的穷逼表示不知道24时制是00:00—23:59,12时制是01:00—12:59。

 1 #include<cstdio>
 2 #include<iostream>
 3 using namespace std;
 4 char c[30];
 5 int n, a, b;
 6 void judge24()
 7 {
 8     int ans = 0;
 9     int a = (c[0] - '0') * 10 + c[1] - '0';
10     int b = (c[3] - '0') * 10 + c[4] - '0';
11     if(a >= 24) ans++;
12     if(b >= 60) ans++;
13     printf("%d\n", ans);
14 }
15 void judge12()
16 {
17     int ans = 0;
18     int a = (c[0] - '0') * 10 + c[1] - '0';
19     int b = (c[3] - '0') * 10 + c[4] - '0';
20     if(a > 12 || a < 1) ans++;
21     if(b >= 60) ans++;
22     printf("%d\n", ans);    
23 }
24 int main()
25 {
26     scanf("%d", &n);
27     scanf("%s", c);
28     if(n == 12) judge12();
29     if(n == 24) judge24();
30     return 0;
31 }
View Code

猜你喜欢

转载自www.cnblogs.com/Jony-English/p/12933288.html