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. 20155203 2016-2017-2 《Java程序设计》第7周学习总结

    20155203 2016-2017-2 <Java程序设计>第6周学习总结 教材学习内容总结 1.Lambda表达式.(使用interface函数接口) 2.Lambda的方法参考Met ...

  2. Javascript - LayUI库的流加载

    LayUI库的流加载 用的LayUI-v2.2.45,将整个包解压缩后添加到项目,引入两个文件即可,不需要引入Jquery,此库自带: <link href="../js/layui- ...

  3. 查询总结、HQL语法、QBC(QueryByCriteria)深入学习

    1.查询总结 在之前的批量查询练习的时候练习基本五种查询方法的使用: 1.OID查询---根据对象ID进行查询 2.对象属性导航查询: obj.getXXX 3.HQL查询:Query对象查询 4.Q ...

  4. oracel回收站清理

    从powerdesigner中往oracle中导入表,出现了很多类似“BIN$Z35FPY7eFZDgUKjAC94NkA==$0 ”这样的表名, 原因是删除表的时候没有彻底的删除表,而是把表放入回收 ...

  5. Centos6.5下rsync+inotify的配置详解

    Centos 6.5配置rsync+inotify实现文件实时同步 1.安装rsync(两台机器执行相同的步骤) yum install gcc yum install rsyncd xinetd - ...

  6. Shape Factory

    Factory is a design pattern in common usage. Implement a ShapeFactory that can generate correct shap ...

  7. 电容充放电时间常数RC计算方法

    进入正题前,我们先来回顾下电容的充放电时间计算公式,假设有电源Vu通过电阻R给电容C充电,V0为电容上的初始电压值,Vu为电容充满电后的电压值,Vt为任意时刻t时电容上的电压值,那么便可以得到如下的计 ...

  8. springmvc接收jquery提交的数组数据

    var selectedUsers = $('#users').tagbox('getValues'); if (selectedUsers.length > 0) { $.post(appPa ...

  9. java虚拟机规范(se8)——java虚拟机结构(四)

    2.7 对象的表示 java虚拟机并不要求对象满足任何特定的内部结构. 在Oracle的一些Java虚拟机实现中,对类实例的引用是指向句柄的指针,该句柄本身是一对指针:一个指向包含对象方法的表和指向表 ...

  10. [原创]win7环境下搭建eclipse+python+django开发环境

    一)工具下载 a)eclipse(最新版4.3.1)官网下载地址 http://www.eclipse.org/downloads/ b)python (2.X版本)官网下载地址 http://pyt ...