View Code of Problem 3310

#include <bits/stdc++.h>
using namespace std;

int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		string s;
		stringstream s1;
		cin>>s;
		string y,m,d,h,f,ss;
		y=s.substr(0,4);
		m=s.substr(5,2);
		d=s.substr(8,2);
		h=s.substr(11,2);
		f=s.substr(14,2);
		ss=s.substr(17,2);
		s1<<h;
		int hour;
		s1>>hour;
//	cout<<hour+1<<endl;
if(hour==0)
{
	hour+=12;
	cout<<y<<"/"<<m<<"/"<<d<<"-";
	printf("%02d",hour);
	cout<<":"<<f<<":"<<ss<<"am"<<endl;
//	printf("%s/%s/%s-%02d:%s:%sam\n",y,m,d,f,ss);
}
else if(hour>12)
{
	hour-=12;
cout<<y<<"/"<<m<<"/"<<d<<"-";
	printf("%02d",hour);
	cout<<":"<<f<<":"<<ss<<"pm"<<endl;
}
else if(hour==12)
{
	cout<<y<<"/"<<m<<"/"<<d<<"-";
	printf("%02d",hour);
	cout<<":"<<f<<":"<<ss<<"pm"<<endl;
}


	
	}
	return 0;
 } 

Double click to view unformatted code.


Back to problem 3310