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 pathcitystate3.java
More file actions
65 lines (52 loc) · 1.4 KB
/
citystate3.java
File metadata and controls
65 lines (52 loc) · 1.4 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
import java.io.*;
import java.util.*;
public class citystate3 {
public static double decify(int num) {
return 0.01*num;
}
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
BufferedReader f=new BufferedReader(new FileReader("citystate.in"));
PrintWriter pw=new PrintWriter(new BufferedWriter(new FileWriter("citystate.out")));
int N=Integer.parseInt(f.readLine());
String tmpStr;
int [][] freq =new int[26*26][26*26];
int [] idx1 = new int[N];
int state, city;
int Nidx=0;
StringTokenizer st;
for(int i=0;i<N;i++) {
st=new StringTokenizer(f.readLine());
tmpStr=st.nextToken();
state=26*(tmpStr.charAt(0)-'A')+tmpStr.charAt(1)-'A';
tmpStr=st.nextToken();
city=26*(tmpStr.charAt(0)-'A')+tmpStr.charAt(1)-'A';
if(city!=state)
{
if(freq[city][state]==0)
idx1[Nidx++]=(city<<10)+state;
freq[city][state]++;
}
//System.out.println("READ");
}
int count=0;
/*
for(int i=0;i<26*26;i++)
{
for(int j=i+1;j<26*26;j++)
{
count+=freq[i][j]*freq[j][i];
}
}*/
for(int i=0;i<Nidx;i++)
{
city=idx1[i]>>10;
state=idx1[i]&1023;
//System.out.println("city:"+city+" state:"+state +" " +idx1[i]);
count+=freq[city][state]*freq[state][city];
}
pw.println(count/2);
pw.close();
f.close();
}
}