A. Broken Clock

题目连接:

http://codeforces.com/contest/722/problem/A

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<bits/stdc++.h>
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<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<s2.size();k++)
if(s2[k]!=s[k])tmp++;
if(ans1>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<s2.size();k++)
if(s2[k]!=s[k])tmp++;
if(ans1>tmp)ans1=tmp,ans2=s2;
}
}
}
cout<<ans2<<endl;
}

Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) A. Broken Clock 水题的更多相关文章

  1. Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) A B C D 水 模拟 并查集 优先队列

    A. Broken Clock time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  2. Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) B. Verse Pattern 水题

    B. Verse Pattern 题目连接: http://codeforces.com/contest/722/problem/B Description You are given a text ...

  3. Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)

    A. Broken Clock time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  4. Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)(set容器里count函数以及加强for循环)

    题目链接:http://codeforces.com/contest/722/problem/D 1 #include <bits/stdc++.h> #include <iostr ...

  5. 二分 Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) D

    http://codeforces.com/contest/722/problem/D 题目大意:给你一个没有重复元素的Y集合,再给你一个没有重复元素X集合,X集合有如下操作 ①挑选某个元素*2 ②某 ...

  6. 线段树 或者 并查集 Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) C

    http://codeforces.com/contest/722/problem/C 题目大意:给你一个串,每次删除串中的一个pos,问剩下的串中,连续的最大和是多少. 思路一:正方向考虑问题,那么 ...

  7. Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) D. Generating Sets 贪心

    D. Generating Sets 题目连接: http://codeforces.com/contest/722/problem/D Description You are given a set ...

  8. Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) C. Destroying Array 带权并查集

    C. Destroying Array 题目连接: http://codeforces.com/contest/722/problem/C Description You are given an a ...

  9. Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) C. Destroying Array

    C. Destroying Array time limit per test 1 second memory limit per test 256 megabytes input standard ...

随机推荐

  1. 前端 ajax 改写登录界面

    SSM 整合项目开发到一个阶段,想慢慢地把前台框架等技术引入进来 突然碰到一个困惑好久的问题: ajax 替换原本 form 表单 post 提交登录: 一直 404 错误,心塞.... 最后发现原来 ...

  2. [整理]解析Json需要设置Mime

    IIS6.0 1.打开IIS添加Mime项 关联扩展名:*.json内容类型(MIME):application/x-javascript 2.添加映射: 位置在IIS对应站点右键属性:”主目录”-” ...

  3. 关于An internal error occurred during: "Launching MVC on Tomcat 6.x". java.lang.NullPointerException异常处理

    一大早上来启动打开myeclipse就报一个这样的错误An internal error occurred during: "Launching MVC on Tomcat  6.x&quo ...

  4. 04 uni-app框架学习:禁用顶部原生导航栏

    1.在pages.json中配置 比如要首页禁用 就在首页这个选项里 加上这几句代码 2.效果如下

  5. MapReduce--shuffle

    一.Shuffle简介 Shuffle的正常意思是洗牌或弄乱,shuffle的大致范围就是把map task的输出结果有效的传送到Reduce端.也可以这样理解,shuffle描述着数据从map ta ...

  6. Python学习二|Python的一些疑问

    最近写了一点Python代码,作为一个java程序员,面对Python这么便捷的语言不禁有点激动.不过呢,有时候也会遇到一些无法理解的东西. 例如: er = [[1,2,3], [4,5,6], [ ...

  7. thymeleaf:访问静态方法

    <p class="left tel" th:if="${#strings.startsWith(T(net.common.util.tool.common.Req ...

  8. day22-23作业

    1.字节流  字符流    2.read()  3.-1  4.System.out  5.InputStream  6.OutputStream 1.IO流按流向分为输入流和输出流,即输入流和输出流 ...

  9. elasticsearch6.3.2之x-pack6.3.2破解安装并配合kibana使用

    原文链接:https://www.plaza4me.com/article/20180825223826278 由于在elasticsearch在6.3版本之后x-pack是默认安装好的,所以不再需要 ...

  10. 【mysql】source导入多个文件

    在mysql中,可以将表导出为sql文件,比如1.sql, 2.sql等等. 导入一个文件: source /home/somepath/.sql 那么问题来了,如果我想一次导入100个文件呢?总不能 ...