A. Broken Clock

time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
output:standard output

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.

Examples

input

24
17:30

output

17:30

input

12
17:30

output

07:30

input

24
99:99

output

09:09
 //2016.10.1
#include <iostream>
#include <cstdio>
#include <cstring> using namespace std; int main()
{
int format, hh, mm;
while(scanf("%d", &format)!=EOF)
{
scanf("%d:%d", &hh, &mm);
if(format==)
{
if(hh == )hh++;
else if(hh< || hh > )
{
if(hh% == )hh = ;
else hh %= ;
}
if(mm< || mm > )mm%=;
printf("%02d:%02d\n", hh, mm);
}else
{
if(hh< || hh > )hh%=;
if(mm< || mm > )mm%=;
printf("%02d:%02d\n", hh, mm);
}
} return ;
}

CodeForces 722A的更多相关文章

  1. CodeForces 722A Broken Clock (水题)

    题意:给定一个时间,然后改最少的数字,使得它成为12进制或者24进制. 析:24进制主要判是不是大于23,如果是把第一位变成0,12进制判是不是大于12,如果是再看第二位是不是0,是0,第一位变成1, ...

  2. 【26.34%】【codeforces 722A】Broken Clock

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  3. Codeforces水题集合[14/未完待续]

    Codeforces Round #371 (Div. 2) A. Meeting of Old Friends |B. Filya and Homework A. Meeting of Old Fr ...

  4. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  5. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  6. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  7. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  8. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  9. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

随机推荐

  1. 制作双击可运行的jar

    http://www.cnblogs.com/ylawrence3/archive/2009/11/08/1350645.html

  2. iOS 图片拉伸

    UIImage *img = [UIImage imageNamed:@"CGUnwrapRed_2"]; img = [img stretchableImageWithLeftC ...

  3. 使用RGBa和Filter实现不影响子元素的CSS透明背景

    点击查看原文 问题 如果我们想要一个元素拥有半透明的背景,我们有两个选择: 使用CSS和 opacity 做一张 24-bit PNG 背景图片 在CSS中使用opacity有两个问题,一是为了适应所 ...

  4. php smarty

     摘自:http://linux.chinaitlab.com/PHP/38324.html 刚开始接触模版引擎的 PHP 设计师,听到 Smarty 时,都会觉得很难.其实笔者也不例外,碰都不敢碰一 ...

  5. HDU 3903 Trigonometric Function

    这题真难,并不会推理... #include<cstdio> #include<cstring> #include<cmath> #include<algor ...

  6. Windows录音API学习笔记(转)

    源:Windows录音API学习笔记 Windows录音API学习笔记 结构体和函数信息  结构体 WAVEINCAPS 该结构描述了一个波形音频输入设备的能力. typedef struct { W ...

  7. 64脚和小于64脚的STM32进行AD时注意,参照电源处理方法(转)

    源:64脚和小于64脚的STM32进行AD时注意,参照电源处理方法 请注意,ADC_IN17上没有内部基准,将其说成基准电压概念不对. 所以横线以下的理解不对,如果将其做为参考,则其电压假定按1.2V ...

  8. sql2000数据库误删除后自行恢复二次覆盖成功恢复

    sql2000数据库误删除后自行恢复二次覆盖成功恢复 [数据恢复故障描述] 今天接到一个客户电话,他的速达sql2000数据库,数据库误删除了,关键之前还没有备份过.他就想自己尝试恢复,使用网上下载的 ...

  9. C语言-结构体

    C语言中数组是把相同类型的数据类型的变量集中在一起了,而结构体则是把不同类型的变量聚集在一起. 结构体也是一种数据类型,但是它是一种自定义的数据类型,也就是说和使用其他数据类型不一样,我们得先定义这种 ...

  10. Jquery的AJAX应用详解

    案例一:取得服务端当前时间 简单形式:jQuery对象.load(url),返回结果自动添加到jQuery对象代表的标签中间 <body> 当前时间: <span id=" ...