【ACM】poj_2210_Metric Time_201308011933
Metric Time
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 2550 Accepted: 783
Description
The Metric Time is one of the most important points of PSOS Election Programme. The Time can be much easier calculated in operating systems. These systems are then more stable, which meets the main goal of the Party.
The length of one day is the same as with the "classic" time. The day is divided into 10 metric hours, each of them into 100 metric minutes, and each minute into 100 metric seconds. 10 metric days form one metric week, 10 metric weeks give one metric month, 10 metric months are called metric year. It is obvious this Metric Time is much better than the classic one.
Some opponent parties often complain that the Metric Time has also some drawbacks. First of all, it would be very difficult to change to the new time. PSOS Chairman decided to solve these problems all at once. He plans to publish a freeware utility which will be able to convert between the time formats. Your goal is to write one half of this utility, the program which converts classic time to Metric Time. Metric hours, metric minutes, and metric seconds are counted starting with zero, as usual. Metric days and metric months start with one. There exist metric year zero. The metric seconds should be rounded to the nearest smaller integer value. Assume that 0:0:0 1.1.2000 classic time is equal to 0:0:0 1.1.0 Metric Time.
Note that the classic year is leap, if it is an integer multiple of 4. The only exception are years divisible by 100 - they are leap only if they are an integer multiple of 400. For example, leap years are 1996, 2400, and 2000; leap years are not 1900, 2300, 2002.
Input
At the first line there is a positive integer N stating the number of assignments to follow. Each assignment consists of exactly one line in the form "hour:minute:second day.month.year" which is the date in the classic form (usual in most of European countries). The date is always valid, 2000 <= year <= 50000.
Output
The program must print exactly one line for each assignment. The line should have the form "mhour:mmin:msec mday.mmonth.myear" which is the Metric Time equal to the specified classic time.
Sample Input
7
0:0:0 1.1.2000
10:10:10 1.3.2001
0:12:13 1.3.2400
23:59:59 31.12.2001
0:0:1 20.7.7478
0:20:20 21.7.7478
15:54:44 2.10.20749
Sample Output
0:0:0 1.1.0
4:23:72 26.5.0
0:8:48 58.2.146
9:99:98 31.8.0
0:0:1 100.10.2000
0:14:12 1.1.2001
6:63:0 7.3.6848
#include <stdio.h>
#include <string.h>
int isRunNian(int n)
{
if(n%400==0||(n%4==0&&n%100!=0))
return 1;
else
return 0;
}//判断是否为闰年
int DiJiTian(int y,int m,int d)
{
int i,total=0;
for(i=1;i<m;i++)
{
if(i==1||i==3||i==5||i==7||i==8||i==10||i==12)
total+=31;
if(i==4||i==6||i==9||i==11)
total+=30;
if(i==2)
{
if(isRunNian(y))
total+=29;
else
total+=28;
}
}
for(i=2000;i<y;i++)
{
if(isRunNian(i))
total+=366;
else
total+=365;
}
total+=d-1;
return total;
}//判断该日期为这一年的第几天
int classictime(int n)
{
//n=99999;
int i,j,k,m;
m=i=j=k=0;
m=n/100000;
n%=100000;
i=n/10000;
n%=10000;
j=n/100;
n%=100;
k=n;
printf("%d:%d:%d ",i,j,k);
return m;
}
int classicdate(int n)
{
//n=1000;
int i,j,k,m;
i=0;j=1;k=1;m=n;
i=m/1000;
m%=1000;
j+=m/100;
m%=100;
k+=m;
printf("%d.%d.%d\n",k,j,i);
return 0;
}
int main()
{
int N;
scanf("%d",&N);
getchar();
while(N--){
char s[22];
int a[8]={0};
int i,j,t,date,total,time;
total=time=t=0;
gets(s);
//puts(s);
for(j=0,i=0;i<strlen(s);i++)
{
if(s[i]!=':'&&s[i]!='.'&&s[i]!=' ')
t=t*10+s[i]-'0';
else
{a[j++]=t;t=0;continue;}
//printf("%d\n",t);
}
a[j]=t;
date=DiJiTian(a[5],a[4],a[3]);
//printf("%d\n",date);
total=(int)(date*0.864);
time=date*864-total*1000;
time*=100;
time+=a[0]*3600+a[1]*60+a[2];
total+=(time/100000);
time%=100000;
total+=classictime(time);
classicdate(total);
//printf("%d\n",time);
//for(i=0;i<6;i++)
//printf("%d ",a[i]);
}
return 0;
}
//错误代码
#include <stdio.h>
#include <string.h>
int isRunNian(int n)
{
if(n%400==0||(n%4==0&&n%100!=0))
return 1;
else
return 0;
}//判断是否为闰年
int DiJiTian(int y,int m,int d)
{
int i,total=0;
for(i=1;i<m;i++)
{
if(i==1||i==3||i==5||i==7||i==8||i==10||i==12)
total+=31;
if(i==4||i==6||i==9||i==11)
total+=30;
if(i==2)
{
if(isRunNian(y))
total+=29;
else
total+=28;
}
}
for(i=2000;i<y;i++)
{
if(isRunNian(i))
total+=366;
else
total+=365;
}
total+=d-1;
return total;
}//判断该日期为这一年的第几天
int classictime(int n)
{
//n=99999;
int i,j,k;
i=j=k=0;
n%=100000;
i=n/10000;
n%=10000;
j=n/100;
n%=100;
k=n;
printf("%d:%d:%d ",i,j,k);
return 0;
}
int classicdate(int n)
{
//n=1000;
int i,j,k,m;
i=0;j=1;k=1;m=n;
i=m/1000;
m%=1000;
j+=m/100;
m%=100;
k+=m;
printf("%d.%d.%d\n",k,j,i);
return 0;
}
int main()
{
int N;
scanf("%d",&N);
getchar();
while(N--){
char s[22];
int a[8]={0};
int i,j,t,date,total,time;
total=time=t=0;
gets(s);
//puts(s);
for(j=0,i=0;i<strlen(s);i++)
{
if(s[i]!=':'&&s[i]!='.'&&s[i]!=' ')
t=t*10+s[i]-'0';
else
{a[j++]=t;t=0;continue;}
//printf("%d\n",t);
}
a[j]=t;
date=DiJiTian(a[5],a[4],a[3]);
//printf("%d\n",date);
time=(a[0]*3600+a[1]*60+a[2])/0.864;
classictime(time);
classicdate(date);
//printf("%d\n",time);
//for(i=0;i<6;i++)
//printf("%d ",a[i]);
}
return 0;
}
//AC
#include<stdio.h>
int main()
{
int m[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int year,mon,day,hour,min,sec,myear,mmon,mday,mhour,mmin,msec;
int i,n;
scanf("%d",&n);
while(n--)
{
scanf("%d%*c%d%*c%d%*c%d%*c%d%*c%d",&hour,&min,&sec,&day,&mon,&year);//这种输入比较好,值得学习
for(i=1,m[0]=0;i<mon;i++)
m[0]+=m[i];
if(mon>2)
if(year%4==0&&year%100!=0||year%400==0)
m[0]++;
for(i=2000;i<year;i+=4)
if(i%100!=0||i%400==0)
m[0]++;
m[0]+=(year-2000)*365+day-1;
myear=m[0]/1000;
m[0]%=1000;
mmon=m[0]/100;
mday=m[0]%100;
m[0]=(hour*3600+min*60+sec)/0.864;
mhour=m[0]/10000;
m[0]%=10000;
mmin=m[0]/100;
msec=m[0]%100;
printf("%d:%d:%d %d.%d.%d\n",mhour,mmin,msec,mday+1,mmon+1,myear);
}
return 0;
}
//参考的别人的代码
【ACM】poj_2210_Metric Time_201308011933的更多相关文章
- 高手看了,感觉惨不忍睹——关于“【ACM】杭电ACM题一直WA求高手看看代码”
按 被中科大软件学院二年级研究生 HCOONa 骂为“误人子弟”之后(见:<中科大的那位,敢更不要脸点么?> ),继续“误人子弟”. 问题: 题目:(感谢 王爱学志 网友对题目给出的翻译) ...
- 【ACM】HDU1008 Elevator 新手题前后不同的代码版本
[前言] 很久没有纯粹的写写小代码,偶然想起要回炉再来,就去HDU随便选了个最基础的题,也不记得曾经AC过:最后吃惊的发现,思路完全不一样了,代码风格啥的也有不小的变化.希望是成长了一点点吧.后面定期 ...
- 【ACM】魔方十一题
0. 前言打了两年的百度之星,都没进决赛.我最大的感受就是还是太弱,总结起来就是:人弱就要多做题,人傻就要多做题.题目还是按照分类做可能效果比较好,因此,就有了做几个系列的计划.这是系列中的第一个,解 ...
- 【ACM】那些年,我们挖(WA)过的最短路
不定时更新博客,该博客仅仅是一篇关于最短路的题集,题目顺序随机. 算法思想什么的,我就随便说(复)说(制)咯: Dijkstra算法:以起始点为中心向外层层扩展,直到扩展到终点为止.有贪心的意思. 大 ...
- 【ACM】不要62 (数位DP)
题目:http://acm.acmcoder.com/showproblem.php?pid=2089 杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer).杭州交通管理局经常会扩充一些的士车牌照,新 ...
- 【Acm】八皇后问题
八皇后问题,是一个古老而著名的问题,是回溯算法的典型例题. 其解决办法和我以前发过的[算法之美—Fire Net:www.cnblogs.com/lcw/p/3159414.html]类似 题目:在8 ...
- 【ACM】hud1166 敌兵布阵(线段树)
经验: cout 特别慢 如果要求速度 全部用 printf !!! 在学习线段树 内容来自:http://www.cnblogs.com/shuaiwhu/archive/2012/04/22/24 ...
- 【acm】杀人游戏(hdu2211)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2211 杀人游戏 Time Limit: 3000/1000 MS (Java/Others) M ...
- 【ACM】How many prime numbers
http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=2§ionid=1&problemid=2 #inclu ...
随机推荐
- FileZilla Client 免费又好用的ftp工具
设置文件同步关联(这个功能很好用) 很好用,很方便! 防止掉线 编辑->设置
- Android+Jquery Mobile学习系列(6)-个人信息设置
本节开始,进行代码的实战练习.我的这个App是管理保险客户信息的,数据采用Sqlite存储在本地手机上,第一次使用需要先登记自己的个人信息,这个功能非常简单,也无关紧要,我是拿这个练手,方便做后面复杂 ...
- elasticsearch _field_stats 源码分析
_field_stats 实现的功能:https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-field-stats.ht ...
- Moco模拟服务器实现请求&响应 (一)
接口测试Moco工具 1.使用Moco模拟,首先需要下载Moco 的jar 包,下载链接: http://central.maven.org/maven2/com/github/dreamhead/m ...
- Django day08 多表操作 (四) 一对多, 多对多连续跨表查询
一对多 # 基于双下划线的一对多查询 # 查询出版社为上海出版社的所有图书 # ret = Publish.objects.filter(name='上海出版社').values('book__nam ...
- ACM_来自不给标题的菜鸟出题组(巴什博弈+素数判定)
来自不给标题的菜鸟出题组 Time Limit: 2000/1000ms (Java/Others) Problem Description: 大B和小b合作出一道程序设计月赛的题,他们的想法是给定一 ...
- 35个jquery小技巧
1. 禁止右键点击 ? 1 2 3 4 5 $(document).ready(function(){ $(document).bind("contextmenu",fun ...
- https 结合使用 对称加密和非对称加密
(一)对称加密(Symmetric Cryptography) ---共享密钥加密 对称加密是最快速.最简单的一种加密方式,加密(encryption)与解密(decryption)用的是同样的密钥( ...
- 全局设置border-box
全局设置 border-box 很好,更符合我们通常对一个「盒子」尺寸的认知.,其次它可以省去一次又一次的加加减减,它还有一个关键作用——让有边框的盒子正常使用百分比宽度.但是使用了 border-b ...
- Android Retrofit 2.0文件上传
Android Retrofit 实现(图文上传)文字(参数)和多张图片一起上传 使用Retrofit进行文件上传,肯定离不开Part & PartMap. public interface ...