博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) A. Broken Clock 水题
阅读量:6979 次
发布时间:2019-06-27

本文共 2103 字,大约阅读时间需要 7 分钟。

A. Broken Clock

题目连接:

Description

You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.

You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.

For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39

Input

The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.

The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.

Output

The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.

Sample Input

24

17:30

Sample Output

17:30

Hint

题意

12小时制的话,时钟是从1开始到12的。

24小时制的话,时钟是从0开始到23的

然后给你一个小时制度,然后再给你一个时间,问你这个时间是否合法,如果不合法的话,你需要修改最少的数字,使得这个时间合法 。

题解:

智力低下的人,就像我一样,直接暴力枚举就好了,不要去想那么多……

代码

#include
using namespace std;int main(){ int h;scanf("%d",&h); string s;cin>>s; int ans1 = 1e9; string ans2; if(h==24){ for(int i=0;i
tmp)ans1=tmp,ans2=s2; } } } else { for(int i=1;i<=h;i++) { for(int j=0;j<60;j++) { string s2; s2+=(i/10)%10+'0'; s2+=i%10+'0'; s2+=':'; s2+=(j/10)%10+'0'; s2+=j%10+'0'; int tmp = 0; for(int k=0;k
tmp)ans1=tmp,ans2=s2; } } } cout<
<

转载地址:http://fmupl.baihongyu.com/

你可能感兴趣的文章
No.6 PHP的基本配置与优化
查看>>
javabean属性的类型选择包装类还是基本数据类型
查看>>
使用T-SQL语句操作数据表-更新数据
查看>>
关于SAP BW提示“Carry out repairs in non-original only
查看>>
中国书法的造型元素与原理 刘彦湖
查看>>
20170507Linux七周二次课 io监控free ps 网络状态 抓包
查看>>
26期20180601目录管理
查看>>
26期20180716 iptables规则备份恢复 firewalld zone
查看>>
营销自动化为什么能吸引企业的喜欢?它有何魅力?
查看>>
网络分流器-网络分流器IP网络路由交换测试技术探讨
查看>>
部分人说 Java 的性能已经达到甚至超过 C++,是真的吗?
查看>>
网络安全技术分析:DDoS的攻与防
查看>>
LNMP安装配置
查看>>
什么是机器人底盘 答案在这里!
查看>>
SNMP 协议 OID的使用
查看>>
【CSS3教程】CSS3基础&常用技巧&实例集合
查看>>
面试题:2018最全Redis面试题整理
查看>>
引用头文件#include <queue>出错
查看>>
koa2 简单了解
查看>>
阿里P7架构师告诉你Java架构师必须知道的 6 大设计原则
查看>>