代码
#include<bits/stdc++.h>
using namespace std;
long long f[114514];
int t,n;
void read()
{
int h,m;
char tmp[114514];
cin>>tmp;
int l=0;
if(tmp[1]==':')
h=tmp[0]-'0',l=0;
else if(tmp[2]==':')
h=(tmp[0]-'0')*10+tmp[1]-'0',l=1;
m=(tmp[l+2]-'0')*10+tmp[l+3]-'0';
l=l+3;
if(tmp[l+1]=='p'&&h!=12)
h+=12;
h-=8;
f[h*60+m]--;
l+=4;
if(tmp[l+1]==':')
h=tmp[l]-'0',l+=2;
else if(tmp[l+2]==':')
h=(tmp[l]-'0')*10+tmp[l+1]-'0',l+=3;
m=(tmp[l]-'0')*10+tmp[l+1]-'0';
l+=2;
if(tmp[l]=='p'&&h!=12)
h+=12;
h-=8;
f[h*60+m]++;
}
void print(int x)
{
int h=x/60+8;
int m=x%60;
int tmp=h%12;
if(tmp<10)
cout<<0;
if(tmp==0)
tmp=12;
cout<<tmp;
cout<<":";
if(m<10)
cout<<0;
cout<<m;
if(h<12)
cout<<"am";
else
cout<<"pm";
}
int main()
{
cin>>t;
int k=t;
while(k--)
{
cin>>n;
for(int i=1;i<=n;i++)
{
read();
}
}
for(int i=1;i<=13*60;i++)
f[i]+=f[i-1];
for(int i=0;i<=13*60;i++)
{
if(f[i]==(-t)&&(i==0||f[i-1]!=(-t)))
{
print(i);
cout<<'-';
}
if((f[i]!=(-t)&&f[i-1]==(-t))||(i==13*60&&f[i]==(-t)))
{
print(i);
cout<<'\n';
}
}
return 0;
}