您的位置:首页 > 其它

poj 3751 时间日期格式转换

2014-07-10 15:13 369 查看
题目链接:http://poj.org/problem?id=3751

题目大意:按照要求的格式将输入的时间日期进行转化。

#include <iostream>
#include <cstdio>
using namespace std;
int main ()
{
int t;
cin>>t;
while (t--)
{
int y,m,d,xs,fz,ms;
char ch1,ch2,ch3,ch4,ch5;
//scanf("%d/%d/%d-%d:%d:%d",y,m,d,xs,fz,ms);
//printf ("%d/%d/%d-%d:%d:%d",m,d,y,xs,fz,ms);
scanf("%d%c%d%c%d%c%d%c%d%c%d",&y,&ch1,&m,&ch2,&d,&ch3,&xs,&ch4,&fz,&ch5,&ms);
char q,p;
if (xs>=12)
{
q='p';
p='m';
}
else
{
q='a';
p='m';
}
if (xs==0)
xs=12;
xs=(xs>12?xs-12:xs);
printf ("%02d/%02d/%04d-%02d:%02d:%02d%c%c\n",m,d,y,xs,fz,ms,q,p);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: