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. Windows上mxnet实战深度学习:Neural Net

    前提: 假设已经在Windows上安装配置好mxnet和python语言包. 假设mxnet安装目录为D:\mxnet 假设已安装好wget 可以参考 这篇文章 打开Windows的命令提示符: 执行 ...

  2. SSL 通信原理及Tomcat SSL 双向配置

    SSL 通信原理及Tomcat SSL 双向配置 目录1 参考资料 .................................................................. ...

  3. The 2014 ACMICPC Asia Regional Beijing Online

    [A]极角排序+树状数组 [B]计算几何,凸包(队友已出) [C]-_-///不懂 [D]数论,概率密度 [E]图的连通性+Floyed传递闭包+bitset [F]贪心 [G]签到题 [H]区间维护 ...

  4. 解决ubuntu server mysql load data infile 导入本地文件ERROR 1148 (42000)错误。

    问题:在ubuntu server 上使用apt-get 安装完 mysql 使用 load data infile 出现错误,错误代码如下: ERROR (): The used command i ...

  5. iOS查错机制

    转自: http://mp.weixin.qq.com/s?__biz=MjM5OTM0MzIwMQ==&mid=404478233&idx=2&sn=ae55d4f70fce ...

  6. The Willpower Instinct

    https://book.douban.com/subject/7043452/ 1.冥想2.健康饮食(低GI.素食为主,未加工食物为主).低GI食物使血糖稳定(蛋白.麦片.粗纤谷类.豆类.水果蔬菜) ...

  7. 0115percona-toolkit安装教程

    一.percona-toolkit简介percona-toolkit是一组高级命令行工具的集合,用来执行各种通过手工执行非常复杂和麻烦的mysql和系统任务,这些任务包括: 检查master和slav ...

  8. golang中container/heap包源码分析

    学习golang难免需要分析源码包中一些实现,下面就来说说container/heap包的源码 heap的实现使用到了小根堆,下面先对堆做个简单说明 1. 堆概念 堆是一种经过排序的完全二叉树,其中任 ...

  9. C# 6.0 11个新特性

    1. 静态using(static using) 静态using声明允许不使用类名直接调用静态方法. The static using declaration allows invoking stat ...

  10. FTP服务器配置部分

    构建基于虚拟用户的vsftpd服务器1.建立虚拟FTP用户的帐号数据库文件 (1) 建立虚拟用户的账户名.密码列表->奇数行为帐号名,偶数行为上一行中帐号的密码 (2) 转化为Berkeley ...