Codeforces A. Broken Clock
//Next Codeforces Round #354 (Div. 2)
#include<bits/stdc++.h>
//#include<cstdio>
//#include<iostream>
//#include<algorithm>
//#include<vector>
//#include<cstring>
//#include<cmath>
//#include<map>
using namespace std;
#define fast ios_base::sync_with_stdio(false)
#define bfast cin.tie(0)
#define outs(x) cout << x << " "
#define outn(x) cout << x << "\n"
#define sf scanf
#define pf printf
#define nl puts("")
typedef long long LL;
typedef vector<int>vii;
typedef vector<LL>vll;
void twelve(int h , int m, char ch)
{
bool hf=false, mf=false;
string uh="10" , um="0";
if(m>=0 and m<=9)
{
um+=char(m+'0');
}
else
{
um = "";
string tmp="";
stringstream ss;
ss << m;
ss >> tmp;
um+=tmp;
}
if(h>=1 and h<=9)
{
uh="0";
uh+=char(h+'0');
}
else
{
uh="";
//uh+=char(h+'0');
string tmp="";
stringstream ss;
ss << h;
ss >> tmp;
uh+=tmp;
if(uh == "0") uh="10";
}
//cout << "uh = " << uh << "\n";
if(h>=1 and h<=12) hf=true;
if(m>=0 and m<=59) mf=true;
if(hf==false and mf==false)
{
bool hzero=false;
if(h==0)
{
hzero=true;
uh="10";
}
if(hzero)
{
if(m > 0)
{
cout << uh << ch << "0" << m%10 << "\n";
}
else
{
cout << uh << ch << um << "\n";
}
}
else
{
cout << "0" << h%10 << ch << "0" << m%10 << "\n";
}
}
else if(hf==false and mf==true)
{
bool hzero=false;
if(h==0)
{
hzero=true;
uh="10";
}
if(hzero)
{
if(m==0)
{
cout << uh << ch << um << "\n";
}
else
{
cout << uh << ch << um << "\n";
}
}
else
{
if(h%10 == 0)
{
uh="10";
cout << uh << ch << um << "\n";
}
else
{
cout << "0" << h%10 << ch << um << "\n";
}
}
}
else if(hf==true and mf==false)
{
cout << uh << ch << "0" << m%10 << "\n";
}
else if(hf==true and mf==true)
{
cout << uh << ch << um << "\n";
}
}
void twentyfour(int h , int m , char ch)
{
bool hf=false, mf=false;
string uh="0" , um="0";
if(m>=0 and m<=9)
{
um+=char(m+'0');
}
else
{
um = "";
string tmp="";
stringstream ss;
ss << m;
ss >> tmp;
um+=tmp;
}
if(h>=0 and h<=9)
{
uh="0";
uh+=char(h+'0');
}
else
{
uh="";
//uh+=char(h+'0');
string tmp="";
stringstream ss;
ss << h;
ss >> tmp;
uh+=tmp;
}
//cout << "uh = " << uh << " um= " << um << "\n";
if(h>=0 and h<=23)hf=true;
if(m>=0 and m<=59)mf=true;
if(hf==true and mf==true)
{
cout << uh << ch << um << "\n";
}
else if(hf==true and mf==false)
{
cout << uh << ch << "0" << m%10 << "\n";
}
else if(hf==false and mf==true)
{
cout << "0" << h%10 << ch << um << "\n";
}
else if(hf==false and mf==false)
{
cout << "0" << h%10 << ch << "0" << m%10 << "\n";
}
}
int main()
{
fast;
int format , i , h , m;
string s ;
while(cin >> format)
{
cin >> h >> s[0] >> m;
if(format == 12)
{
twelve(h , m , s[0]);
}
else
{
twentyfour(h , m , s[0]);
}
}
return 0;
}
#include<bits/stdc++.h>
//#include<cstdio>
//#include<iostream>
//#include<algorithm>
//#include<vector>
//#include<cstring>
//#include<cmath>
//#include<map>
using namespace std;
#define fast ios_base::sync_with_stdio(false)
#define bfast cin.tie(0)
#define outs(x) cout << x << " "
#define outn(x) cout << x << "\n"
#define sf scanf
#define pf printf
#define nl puts("")
typedef long long LL;
typedef vector<int>vii;
typedef vector<LL>vll;
void twelve(int h , int m, char ch)
{
bool hf=false, mf=false;
string uh="10" , um="0";
if(m>=0 and m<=9)
{
um+=char(m+'0');
}
else
{
um = "";
string tmp="";
stringstream ss;
ss << m;
ss >> tmp;
um+=tmp;
}
if(h>=1 and h<=9)
{
uh="0";
uh+=char(h+'0');
}
else
{
uh="";
//uh+=char(h+'0');
string tmp="";
stringstream ss;
ss << h;
ss >> tmp;
uh+=tmp;
if(uh == "0") uh="10";
}
//cout << "uh = " << uh << "\n";
if(h>=1 and h<=12) hf=true;
if(m>=0 and m<=59) mf=true;
if(hf==false and mf==false)
{
bool hzero=false;
if(h==0)
{
hzero=true;
uh="10";
}
if(hzero)
{
if(m > 0)
{
cout << uh << ch << "0" << m%10 << "\n";
}
else
{
cout << uh << ch << um << "\n";
}
}
else
{
cout << "0" << h%10 << ch << "0" << m%10 << "\n";
}
}
else if(hf==false and mf==true)
{
bool hzero=false;
if(h==0)
{
hzero=true;
uh="10";
}
if(hzero)
{
if(m==0)
{
cout << uh << ch << um << "\n";
}
else
{
cout << uh << ch << um << "\n";
}
}
else
{
if(h%10 == 0)
{
uh="10";
cout << uh << ch << um << "\n";
}
else
{
cout << "0" << h%10 << ch << um << "\n";
}
}
}
else if(hf==true and mf==false)
{
cout << uh << ch << "0" << m%10 << "\n";
}
else if(hf==true and mf==true)
{
cout << uh << ch << um << "\n";
}
}
void twentyfour(int h , int m , char ch)
{
bool hf=false, mf=false;
string uh="0" , um="0";
if(m>=0 and m<=9)
{
um+=char(m+'0');
}
else
{
um = "";
string tmp="";
stringstream ss;
ss << m;
ss >> tmp;
um+=tmp;
}
if(h>=0 and h<=9)
{
uh="0";
uh+=char(h+'0');
}
else
{
uh="";
//uh+=char(h+'0');
string tmp="";
stringstream ss;
ss << h;
ss >> tmp;
uh+=tmp;
}
//cout << "uh = " << uh << " um= " << um << "\n";
if(h>=0 and h<=23)hf=true;
if(m>=0 and m<=59)mf=true;
if(hf==true and mf==true)
{
cout << uh << ch << um << "\n";
}
else if(hf==true and mf==false)
{
cout << uh << ch << "0" << m%10 << "\n";
}
else if(hf==false and mf==true)
{
cout << "0" << h%10 << ch << um << "\n";
}
else if(hf==false and mf==false)
{
cout << "0" << h%10 << ch << "0" << m%10 << "\n";
}
}
int main()
{
fast;
int format , i , h , m;
string s ;
while(cin >> format)
{
cin >> h >> s[0] >> m;
if(format == 12)
{
twelve(h , m , s[0]);
}
else
{
twentyfour(h , m , s[0]);
}
}
return 0;
}
Comments
Post a Comment