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. .net remoting 实现通用消息处理窗口

    .net remoting 实现通用消息处理窗口 实现机制是制作一个cmd窗口作为信息展示窗口,主程序将需要展示的信息抛出到cmd窗口显示,以此方式做到消息的展示. 以下是cmd窗口的代码,cmd窗体 ...

  2. 读书笔记——Java IO

    IO流的典型使用方式 1.缓存输入文件 BufferedReader in=new BufferedReader( new FileReader(文件名字) ); String s; StringBu ...

  3. python之路:进阶篇

     > ) {        ;    }    printf(;} print i >>>      >>>  == :    name  ==   ==   ...

  4. FreeBSD 系统的配置.

    SSH 配置 vi /etc/ssh/sshd_config 修改下面的项目 RSAAuthentication yes PermitRootLogin yes PermitEmptypassword ...

  5. Mysql的MySqlDataReader对于MysqlConnection是独占式

    写Secondlife智能体的知识系统小插件的时候遇到的这个问题. 在把某个NPC的全部知识复制给另一个NPC的时候,对数据库操作,为了提升一点效率希望与数据库建立一次连接,全部添加进表以后再断开连接 ...

  6. Protocol Buffers

    今天来介绍一下"Protocol Buffers"(以下简称protobuf)这个玩意儿.本来俺在构思"生产者/消费者模式"系列的下一个帖子:关于生产者和消费者 ...

  7. ICE第四篇-----python版本

    ice文件: module Modipplace {     interface  Ipplace{          string iptoplace(string s);      };   }; ...

  8. POJ3259负环判定

    题意:有n个顶点,m条边,然后有w个洞,过每个洞的时间为-ti,求是否会时光倒流 分析:就是求是否存在负圈,用Bellman-Floyd判定是否存在负圈即可,注意是无向图,所以路径是双向可达的 #in ...

  9. Git for Windows 工具下载及配置

    前言,关于git工具的帖子:http://cn.v2ex.com/t/225027 最终选择了git for windows这个工具,路径为:https://git-for-windows.githu ...

  10. bzoj 4383: [POI2015]Pustynia

    复习了一下线段树优化建图的姿势,在线段树上连边跑拓扑排序 这题竟然卡vector……丧病 #include <bits/stdc++.h> #define N 1810000 using ...