首页 > 其他 > 详细

坏掉的手表

时间:2020-05-21 21:03:14      阅读:55      评论:0      收藏:0      [点我收藏+]

坏掉的手表

时间限制: 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

 

坏掉的手表

原文:https://www.cnblogs.com/Jony-English/p/12933288.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!