首页 > 其他 > 详细

Time Conversion

时间:2015-11-08 14:25:41      阅读:311      评论:0      收藏:0      [点我收藏+]

Problem Statement

You are given time in AM/PM format. Can you convert this into a 24-hour format? 

Input

Input consists of time in the AM/PM format i.e. hh:mm:ssAM or hh:mm:ssPM 
where 01hh12

Sample: 07:05:45PM

Output

You need to print the time in a 24-hour format i.e. hh:mm:ss 
where 00hh23

Sample output for the above input: 19:05:45

Note: Midnight is 12:00:00AM or 00:00:00. Noon is 12:00:00PM.

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */
    string time="";
    cin>>time;
    
    if(time[time.size()-2]==A){
        if(time.substr(0,2)=="12") cout<<"00"<<time.substr(2,time.size()-4)<<endl;
        else cout<<time.substr(0,time.size()-2)<<endl;
    }
    
    if(time[time.size()-2]==P){
        if(time.substr(0,2)=="12") cout<<time.substr(0,time.size()-2)<<endl;
        else cout<<to_string(stoi(time.substr(0,2))+12)<<time.substr(2,time.size()-4)<<endl;
    }
    
    return 0;
}

 

Time Conversion

原文:http://www.cnblogs.com/XingyingLiu/p/4946879.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!