-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParentingPartneringReturns.java
More file actions
70 lines (69 loc) · 1.77 KB
/
ParentingPartneringReturns.java
File metadata and controls
70 lines (69 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import java.util.*;
import java.io.*;
public class ParentingPartneringReturns
{
static class Data
{
int start,end,index;
}
static class Sort implements Comparator<Data>
{
public int compare(Data ob1,Data ob2)
{
return ob1.start - ob2.start ;
}
}
public static String checkandcal(Data arr[],int n, char ch[])
{
int j=-1;
int c=-1;
for(int i=0;i<n;i++)
{
if((j== -1) || (j<= arr[i].start))
{
j=arr[i].end;
ch[arr[i].index]='J';
}
else if((c== -1) || (c<=arr[i].start))
{
c=arr[i].end;
ch[arr[i].index]='C';
}
else
{
return "IMPOSSIBLE";
}
}
return "$";
}
public static void main(String[] args)
{
Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
int t = sc.nextInt();
for (int i = 1; i <= t; ++i)
{
int n=sc.nextInt();
Data arr[]=new Data[n];
for(int x=0;x<n;x++)
{
arr[x]=new Data();
arr[x].start=sc.nextInt();
arr[x].end=sc.nextInt();
arr[x].index=x;
}
Arrays.sort(arr, new Sort());
char ch[]=new char[n];
String s= checkandcal(arr,n,ch);
//System.out.println(ch);
if(!s.equals("$"))
{
System.out.println("Case #"+i+": "+s);
}
else
{
s=ch.toString();
System.out.println("Case #"+i+": "+String.valueOf(ch));
}
}
}
}