View Code of Problem 3310

#include <cstdio>
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
using namespace std;

//题目有毒,不是gc++编译的 to_string stoi都用不了 
int main(){
	int t;
	cin>>t;
	for(int i=0;i<t;i++){
		string str;
		cin>>str;
		string yy,mm,dd,gg,min,ss;
		int hh;
		yy=str.substr(0,4);
		mm=str.substr(5,2);
		dd=str.substr(8,2);
		
		gg=str.substr(11,2);
		stringstream s1(gg);
		s1>>hh;
		min=str.substr(14,2);
		ss=str.substr(17);
		int flag=0;//am
		if(hh>=13){//下午 
			hh-=12;
			flag=1;
		} 
		else if(hh==0){//林晨 
			hh=12;
			flag=0;
		}
		else if(hh==12){
			flag=1;
		} 
		string kk;
		if(!flag)
			kk="am";
		else
			kk="pm";
		bool bb=true;//
		if(hh>10){
			bb=false;
		}
		cout<<mm<<"/"<<dd<<"/"<<yy<<"-";
		if(bb){
			cout<<"0"<<hh;
		}
		else{
			cout<<hh;
		}
		
		cout<<":"<<min<<":"<<ss<<kk<<endl;
		
		
	}
	
	return 0;
}

Double click to view unformatted code.


Back to problem 3310