View Code of Problem 3310

#include <cstdio>
#include <string>
#include <iostream>

using namespace std;

string verse(int hh){
	string kk=to_string(hh);
	int len=kk.length();
	if(len==1){
		return "0"+kk;
	} 
	return kk;
}
int main(){
	int t;
	cin>>t;
	for(int i=0;i<t;i++){
		string str;
		cin>>str;
		string yy,mm,dd,min,ss;
		int hh;
		yy=str.substr(0,4);
		mm=str.substr(5,2);
		dd=str.substr(8,2);
		hh=stoi(str.substr(11,2));
		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";
		cout<<mm<<"/"<<dd<<"/"<<yy<<"-"<<verse(hh)<<":"<<min<<":"<<ss<<kk<<endl;
		
		
	}
	
	return 0;
}
/*
F:\temp\22492793.26323\Main.cc: In function 'std::string verse(int)':
F:\temp\22492793.26323\Main.cc:9: error: 'to_string' was not declared in this scope
F:\temp\22492793.26323\Main.cc: In function 'int main()':
F:\temp\22492793.26323\Main.cc:27: error: 'stoi' was not declared in this scope
*/

Double click to view unformatted code.


Back to problem 3310