|
| 1 | +import java.io.*; |
| 2 | +import java.util.*; |
| 3 | +public class citystate { |
| 4 | + public static double decify(int num) { |
| 5 | + return 0.01*num; |
| 6 | + } |
| 7 | + public static void main(String[] args) throws Exception { |
| 8 | + // TODO Auto-generated method stub |
| 9 | + BufferedReader f=new BufferedReader(new FileReader("citystate.in")); |
| 10 | + PrintWriter pw=new PrintWriter(new BufferedWriter(new FileWriter("citystate.out"))); |
| 11 | + double c1,c2; |
| 12 | + int N=Integer.parseInt(f.readLine()); |
| 13 | + String[] state=new String[N];//INIT storage for state |
| 14 | + String[] city=new String[N];//INIT storage for city |
| 15 | + ArrayList<String> hitstates=new ArrayList<String>(); |
| 16 | + ArrayList<String> hitcities=new ArrayList<String>(); |
| 17 | + StringTokenizer st; |
| 18 | + for(int i=0;i<N;i++) { |
| 19 | + st=new StringTokenizer(f.readLine()); |
| 20 | + state[i]=st.nextToken(); |
| 21 | + city[i]=st.nextToken(); |
| 22 | + //System.out.println("READ"); |
| 23 | + |
| 24 | + } |
| 25 | + int a,b,c,d,e; |
| 26 | + e=0; |
| 27 | + for(int i=0;i<N;i++) { |
| 28 | + a=((int) city[i].charAt(0)) -(int) ' '; |
| 29 | + b=((int) city[i].charAt(1))-(int) ' '; |
| 30 | + c1=(((double)a)+(decify(b))); |
| 31 | + for(int j=i+1;j<N;j++) { |
| 32 | + if(j==i) { |
| 33 | + continue; |
| 34 | + } |
| 35 | + c=((int) state[j].charAt(0))-(int) ' '; |
| 36 | + d=((int) state[j].charAt(1))-(int) ' '; |
| 37 | + c2=(((double)c)+decify(d)); |
| 38 | + |
| 39 | + //System.out.println("Debug "+c1+" , "+c2+" "+state[j].charAt(0)+state[j].charAt(1)+" "+city[i].charAt(0)+city[i].charAt(1)); |
| 40 | + if(c2==c1) { |
| 41 | + |
| 42 | + //System.out.println("HIT"); |
| 43 | + //System.out.println(city[i]+" "+state[j]+" "+city[j]+" "+state[i]); |
| 44 | + if(city[j].equals(state[i].substring(0, 2))){ |
| 45 | + e++; |
| 46 | + } |
| 47 | + } |
| 48 | + } |
| 49 | + } |
| 50 | + //String a1,a2; |
| 51 | + |
| 52 | + |
| 53 | + pw.println(e); |
| 54 | + pw.close(); |
| 55 | + f.close(); |
| 56 | + } |
| 57 | + |
| 58 | + |
| 59 | +} |
0 commit comments