This repository was archived by the owner on Feb 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcitystate2.java
More file actions
68 lines (51 loc) · 1.66 KB
/
citystate2.java
File metadata and controls
68 lines (51 loc) · 1.66 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
import java.io.*;
import java.util.*;
public class citystate2 {
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
BufferedReader f=new BufferedReader(new FileReader("custom.in"));
PrintWriter pw=new PrintWriter(new BufferedWriter(new FileWriter("citystate.out")));
int N=Integer.parseInt(f.readLine());
String[] state=new String[N];//INIT storage for state
String[] city=new String[N];//INIT storage for city
ArrayList<String> hitstates=new ArrayList<String>();
ArrayList<String> hitcities=new ArrayList<String>();
StringTokenizer st;
for(int i=0;i<N;i++) {
st=new StringTokenizer(f.readLine());
state[i]=st.nextToken();
city[i]=st.nextToken();
//System.out.println("READ");
}
int e;
e=0;
for(int i=0;i<N;i++) {
for(int j=0;j<N;j++) {
if(j==i) {
continue;
}
//System.out.println("Debug "+c1+" , "+c2+" "+state[j].charAt(0)+state[j].charAt(1)+" "+city[i].charAt(0)+city[i].charAt(1));
if(city[i].equals(state[j].substring(0, 2))) {
e++;
//System.out.println("HIT");
hitcities.add(city[j]);
hitstates.add(state[i]);
}
}
}
int cancel=0;
for(int i=0;i<hitstates.size();i++) {
//System.out.println(" "+hitstates.get(i).charAt(0)+hitstates.get(i).charAt(1)+" "+hitcities.get(i).charAt(0)+hitcities.get(i).charAt(1));
if(hitcities.get(i).equals(hitstates.get(i).substring(0, 2))) {
cancel++;
//System.out.println("HIT");
}else {
e--;
}
}
e=e-cancel/2;
pw.println(e);
pw.close();
f.close();
}
}