AAAAHH! Overbooked! | ||||||
| ||||||
Description | ||||||
Elaine is excited to begin the school year|so excited, in fact, that she signed herself up to attend several events today (This programming contest, sadly, is not one of them). She may have overdone it, though; she didn't bother to check whether the events she signed up for have con icting times. While you're sitting here in this contest, why not check for her? | ||||||
Input | ||||||
The input consists of multiple test cases. Each test case begins with an integer N, 1 <= N <= 100, on a line by itself denoting the number of events. After that follow N lines giving the start and end times of each event, in hh:mm-hh:mm 24-hour format. The end time is guaranteed to be strictly after the start time. Input is followed by a single line with N = 0, which should not be processed.
For example:
3 09:00-09:50 13:00-17:00 09:50-10:30 2 10:00-11:00 09:00-12:00 0 | ||||||
Output | ||||||
For each test case, print out a single line that says \conflict" (no quotes) if Elaine's events have conflicting times, and \no conflict" (no quotes) otherwise. Assume that Elaine can travel around campus instantaneously, so if an event starts at the same time another event ends, the two events do not conflict. For example:
no conflict conflict | ||||||
Sample Input | ||||||
3 09:00-09:50 13:00-17:00 09:50-10:30 2 10:00-11:00 09:00-12:00 0 | ||||||
Sample Output | ||||||
no conflict conflict | ||||||
Source | ||||||
2010 Stanford Local ACM Programming Contest |
题目大意:
给你n个时间区间,问你是否有冲突的情况出现(时间重叠)
思路:
注意到N比较小,我们直接将24小时进制转化成分钟,记录到vis【】数组中即可,代码实现也比较简单。
#include<stdio.h>
#include<string.h>
using namespace std;
int vis[60*24+20];
int main()
{
int n;
while(~scanf("%d",&n))
{
if(n==0)break;
memset(vis,0,sizeof(vis));
for(int i=0;i<n;i++)
{
int a,b,c,d;
scanf("%d:%d-%d:%d",&a,&b,&c,&d);
int start=a*60+b;
int end=c*60+d;
for(int j=start;j<end;j++)
{
vis[j]++;
}
}
int flag=0;
for(int i=0;i<=24*60+15;i++)
{
if(vis[i]>1)flag=1;
}
if(flag==1)
{
printf("conflict\n");
}
else printf("no conflict\n");
}
}