1
00:12-12:12
2
00:12-12:12
14:00-12:00
1
1
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct time
{
char sta[5],end[5];
}times[110];
bool cmp(time g,time h)
{
return strcmp(g.end,h.end)<0;
}
char e[5],f[5],k[5];
int main()
{
int n;
int a,b,c,d;
int i,j;
int sum;
while(scanf("%d",&n)!=EOF)
{
for(i=0;i<n;i++)
{
scanf("%d%*c%d%*c%d%*c%d",&a,&b,&c,&d);
e[0]=a/10+'0';
e[1]=a%10+'0';
e[2]=b/10+'0';
e[3]=b%10+'0';
f[0]=c/10+'0';
f[1]=c%10+'0';
f[2]=d/10+'0';
f[3]=d%10+'0';
if(strcmp(e,f)<0)
{
strcpy(times[i].sta,e);
strcpy(times[i].end,f);
}
else
{
strcpy(times[i].sta,f);
strcpy(times[i].end,e);
}
}//这里可以直接用int型存储
/*
scanf("%d%c%d%c%d%c%d",&b1,&c,&b2,&c,&e1,&c,&e2);
t[i].b=b1*100+b2;
t[i].e=e1*100+e2;
//这里将小孩开始和结束的时间由小时、分钟两个变量转化为一个方便运算
if(t[i].b>t[i].e)
swap(t[i].b,t[i].e);
*/
sort(times,times+n,cmp);
sum=1;
strcpy(k,times[0].end);
for(i=1;i<n;i++)
{
if(strcmp(times[i].sta,k)>0)
{
sum++;
strcpy(k,times[i].end);
//多区间选取最少公共点
}
}
printf("%d\n",sum);
}
return 0;
} 原文:http://blog.csdn.net/wangluoershixiong/article/details/40677413