topcoder 的一些输入输出格式
自从上年的11月份参加过TC的比赛后,就再也没有参加了,因为它的输入输出格式比较难接受,还有它的页面字体比较小,看得我很辛苦...藉口藉口~~懒而已!不过以后我会尽量去参加的,为了提高自己的编程能力。
以 SRM 144 DIV 2 的 200 分题目为例,记录下两种输入输出格式吧。
|
Problem Statement |
|||||||||||||
|
Computers tend to store dates and times as single numbers which represent the number of seconds or milliseconds since a particular date. Your task in this problem is to write a method whatTime, which takes an int, seconds, representing the number of seconds since midnight on some day, and returns a string formatted as "<H>:<M>:<S>". Here, <H> represents the number of complete hours since midnight, <M> represents the number of complete minutes since the last complete hour ended, and <S> represents the number of seconds since the last complete minute ended. Each of <H>, <M>, and <S> should be an integer, with no extra leading 0's. Thus, if seconds is 0, you should return "0:0:0", while if seconds is 3661, you should return "1:1:1". |
|||||||||||||
|
Definition |
|||||||||||||
|
|||||||||||||
|
Limits |
|||||||||||||
|
|||||||||||||
|
Constraints |
|||||||||||||
|
- |
seconds will be between 0 and 24*60*60 - 1 = 86399, inclusive. |
||||||||||||
|
Examples |
|||||||||||||
|
0) |
|||||||||||||
|
|||||||||||||
|
1) |
|||||||||||||
|
|||||||||||||
|
2) |
|||||||||||||
|
|||||||||||||
|
3) |
|||||||||||||
|
|||||||||||||
JAVA 版
public class Time{
public String whatTime(int seconds){
int h = seconds / 3600;
int m = (seconds % 3600) / 60;
int s = seconds % 3600 - m * 60;
return h + ":" + m + ":" + s;
}
}
C++ 版
#include <iostream>
using namespace std;
class Time{
public:
string whatTime(int seconds)
{
int h = seconds / 3600;
int m = (seconds % 3600) / 60;
int s = seconds % 3600 - m * 60;
char buf[40];
sprintf(buf, "%d:%d:%d", h, m, s);
return string(buf);
}
};
topcoder 的一些输入输出格式的更多相关文章
- [ACM训练] ACM中巧用文件的输入输出来改写acm程序的输入输出 + ACM中八大输入输出格式
ACM中巧用文件的输入输出来改写acm程序的输入输出 经常有见大神们使用文件来代替ACM程序中的IO,尤其是当程序IO比较复杂时,可以使自己能够更专注于代码的测试,而不是怎样敲输入. C/C++代码中 ...
- c++ --> cin和cout输入输出格式
cin和cout输入输出格式 Cout 输出 1>. bool型输出 cout << true <<" or " << false < ...
- C语言第一次作业——输入输出格式
题目1温度转换 本题要求编写程序,计算华氏温度150°F对应的摄氏温度.计算公式:C=5×(F−32)/9,式中:C表示摄氏温度,F表示华氏温度,输出数据要求为整型. 1.实验代码 #include& ...
- hdu ACM Steps Section 1 花式A+B 输入输出格式
acm与oi很大的一个不同就是在输入格式上.oi往往是单组数据,而acm往往是多组数据,而且题目对数据格式往往各有要求,这8道a+b(吐槽..)涉及到了大量的常用的输入输出格式.https://wen ...
- POJ数据的输入输出格式
POJ在评阅习题时需要向程序提供输入数据,并获取程序的输出结果.因此提交的程序需按照每个习题具体的输入输出格式要求处理输入输出.有的时候,测评系统给出程序的评判结果是“数据错误”或“结果错误”,有可能 ...
- Hadoop MapReduce常用输入输出格式
这里介绍MapReduce常用的几种输入输出格式. 三种常用的输入格式:TextInputFormat , SequenceFileInputFormat , KeyValueInputFormat ...
- Hadoop(七):自定义输入输出格式
MR输入格式概述 数据输入格式 InputFormat. 用于描述MR作业的数据输入规范. 输入格式在MR框架中的作用: 文件进行分块(split),1个块就是1个Mapper任务. 从输入分块中将数 ...
- Hadoop学习之常用输入输出格式总结
目的 总结一下常用的输入输出格式. 输入格式 Hadoop可以处理很多不同种类的输入格式,从一般的文本文件到数据库. 开局一张UML类图,涵盖常用InputFormat类的继承关系与各自的重要方法(已 ...
- C语言输入输出格式符
C语言输入输出格式符 printf函数(格式输出函数) 1.一般格式 printf(格式控制,输出表列) 例如:printf("i=%d,ch=%c\n",i,ch); 说明: ( ...
随机推荐
- "Javascript高性能动画与页面渲染"笔记
前言:好久没翻阅我的gmail邮箱了,午休时就打开看了一下,看到InfoQ推荐的一篇名为“Javascript高性能动画与页面渲染”文章,粗略的看了一下,很赞!讲的很详细,对好些细节讲的都很好,很通俗 ...
- [Inside HotSpot] Serial垃圾回收器 (二) Minor GC
Serial垃圾回收器Minor GC 1. DefNewGeneration垃圾回收 新生代使用复制算法做垃圾回收,比老年代的标记-压缩简单很多,所有回收代码都位于DefNewGeneration: ...
- MySQL、Hive以及MySQL Connector/J安装过程
MySQL安装 ①官网下载mysql-server(yum安装) wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch. ...
- java多线程02-----------------synchronized底层实现及JVM对synchronized的优化
java多线程02-----------------synchronized底层实现及JVM对synchronized的优化 提到java多线程,我们首先想到的就是synchronized关键字,它在 ...
- 关于使用uitableview 中cell 来实现uiimageview的复用和图片的异步加载
apple sample lazytableimages 1,首先设置横向显示的uitableview self.customTableview.transform = CGAffineTransfo ...
- 【hql】spring data jpa中 @Query使用hql查询 问题
spring data jpa中 @Query使用hql查询 问题 使用hql查询, 1.from后面跟的是实体类 不是数据表名 2.字段应该用实体类中的字段 而不是数据表中的属性 实体如下 hql使 ...
- 王立平--Gallery:实现图片的左右滑动
<span style="font-size:18px;color:#330033;">package com.main; import android.app.Act ...
- C/C++二进制读写png文件
以下代码只有最简单的读写.地址定位啥的,个别注释中有.如果要改动png的格式甚么的就要再了解一下png的数据结构如果要十进制的话就跟着注释改一下: /*! * \file CC++二进制读写png文件 ...
- linux shell操作
---------------------------------------------------- 原文:http://unix.stackexchange.com/questions/2863 ...
- net spy memcached 使用demo
package memcached; import java.io.IOException; import java.net.InetSocketAddress; import net.spy.mem ...