设为首页 加入收藏

TOP

定义另一个类的成员函数(一)
2013-04-10 11:54:55 来源: 作者: 【 】 浏览:585
Tags:定义 一个 成员 函数

  [C] Minary Fights with Time

  时间限制: 1000 ms 内存限制: 65535 K

  问题描述

  Minary is busy now. As a result, she's fighting with time.

  To serialize every time point she marked, she decide to make every time point to an integer.

  You can imagine that 1970-01-01 00:00:00 GTM(Greenwich Mean Time) is the start. Give you an integer that indicates the total seconds from that time, you should output the time it stands for.

  输入

  This problem contains several cases, input until EOF.

  Every case is an integer(-2^31 ~ 2^31-1) that indicates the total seconds from 1970-1-1 00:00:00 GTM.

  输出

  For every case, you should output its time.

  样例输入

  0

  1111111111

  1363592469

  2147483647

  样例输出

  1970-01-01 00:00:00

  2005-03-18 01:58:31

  2013-03-18 07:41:09

  2038-01-19 03:14:07

  提示

  无来源

  Minary题意: 输入从1970-01-01 00:00:00 到现在的秒数  问现在的时间是什么

  [cpp] view plaincopyprint /*

  struct tm

  {

  int tm_sec;  秒,正常范围0-59, 但允许至61

  int tm_min;  分钟,0-59

  int tm_hour; 小时, 0-23

  int tm_mday; 日,即一个月中的第几天,1-31

  int tm_mon;  月, 从一月算起,0-11  1+p->tm_mon;

  int tm_year;  年, 从1900至今已经多少年 1900+ p->tm_year;

  int tm_wday; 星期,一周中的第几天, 从星期日算起,0-6

  int tm_yday; 从今年1月1日到目前的天数,范围0-365

  int tm_isdst; 日光节约时间的旗标

  };

  需要特别注意的是,年份是从1900年起至今多少年,而不是直接存储如2011年,月份从0开始的,

  0表示一月,星期也是从0开始的, 0表示星期日,1表示星期一。

  */

  #include <iostream>

  #include <cstdio>

  #include <cstring>

  #include <ctime>

  using namespace std;

  int main()

  {

  time_t stamp;/*

  time_t 这种类型就是用来存储从1970-01-01 00:00:00到现在经过了多少秒 这个系统函数就是从1970-01-01 00:00:00开始

  计算的 不可以修改   由于精度问题造成*/

  tm* a;

  while(scanf("%d", &stamp)!=EOF)

  {

  a = gmtime(&stamp);//将time_t表示的时间转换为tm结构体的形式

  printf("%.4d-%.2d-%.2d %.2d:%.2d:%.2d\n",a->tm_year + 1900,

  a->tm_mon + 1,

  a->tm_mday,

  a->tm_hour,

  a->tm_min,

  a->tm_sec

  );

  }

  return 0;

  }

  /*

  struct tm

  {

  int tm_sec;  秒,正常范围0-59, 但允许至61

  int tm_min;  分钟,0-59

  int tm_hour; 小时, 0-23

  int tm_mday; 日,即一个月中的第几天,1-31

  int tm_mon;  月, 从一月算起,0-11  1+p->tm_mon;

  int tm_year;  年, 从1900至今已经多少年 1900+ p->tm_year;

  int tm_wday; 星期,一周中的第几天, 从星期日算起,0-6

  int tm_yday; 从今年1月1日到目前的天数,范围0-365

  int tm_isdst; 日光节约时间的旗标

  };

  需要特别注意的是,年份是从1900年起至今多少年,而不是直接存储如2011年,月份从0开始的,

  0表示一月,星期也是从0开始的, 0表示星期日,1表示星期一。

  */

  #include <iostream>

  #include <cstdio>

  #include <cstring>

  #include <ctime>

  using namespace std;

  int main()

  {

  time_t stamp;/*

  time_t 这种类型就是用来存储从1970-01-01 00:00:00到现在经过了多少秒 这个系统函数就是从1970-01-01 00:00:00开始

  计算的 不可以修改   由于精度问题造成*/

  tm* a;

  while(scanf("%d", &stamp)!=EOF)

  {

  a = gmtime(&stamp);//将time_t表示的时间转换为tm结构体的形式

  printf("%.4d-%.2d-%.2d %.2d:%.2d:%.2d\n",a->tm_year + 1900,

  a->tm_mon + 1,

  a->tm_mday,

  a->tm_hour,

  a->tm_min,

  a->tm_sec

  );

  }

  return 0;

  }

   

首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C++ Builder 处理控件.. 下一篇C++类和堆

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: