-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBUS.java
61 lines (59 loc) · 1.89 KB
/
BUS.java
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
import java.util.*;
import javax.lang.model.util.ElementScanner14;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;
public class BUS {
public static void main(String[] args) throws IOException {
// Scanner sc = new Scanner(System.in);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine().split("")[0]);
while(t>0)
{
t--;
boolean state=true;
String in = br.readLine();
// System.out.println(in);
String[] inp = in.split(" ");
int n = Integer.parseInt(inp[0]);int m = Integer.parseInt(inp[1]); int q = Integer.parseInt(inp[2]);
// System.out.println(n+","+m+","+q);
HashSet<Character> bus = new HashSet<Character>();
for(int i = 0; i<q;i++)
{
String s = br.readLine();
// System.out.println(s);
char sign = s.charAt(0);
// System.out.println(sign);
char person = s.charAt(2);
if(sign == '+')
{
if(bus.contains(person))
{
state = false;
}
else{
bus.add(person);
if(bus.size()>m)
{
state = false;bus.remove(person);
}
}
}
else if(sign == '-')
{
if(!bus.contains(person))
{
state=false;
}
else
bus.remove(person);
}
}
if (!state) {
System.out.println("Inconsistent");
}
else
System.out.println("Consistent");
}
}
}