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 pathcrossroad.java
More file actions
61 lines (51 loc) · 1.34 KB
/
crossroad.java
File metadata and controls
61 lines (51 loc) · 1.34 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
import java.util.*;
import java.io.*;
public class crossroad {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
try{
System.out.println("Starting");
BufferedReader f=new BufferedReader(new FileReader("crossroad.in"));
int N=Integer.parseInt(f.readLine());
int cows=10;
int[] Cows=new int[cows];
for(int i=0;i<cows;i++) {Cows[i]=0;}
int[] prev=new int[cows];
int id;
int pos;
for(int i=0;i<cows;i++) {prev[i]=-1;}
StringTokenizer st;
int total=0;
//int previd;
//previd=-1;
for(int i=0;i<N;i++) {
st=new StringTokenizer(f.readLine());
id=Integer.parseInt(st.nextToken())-1;
pos=Integer.parseInt(st.nextToken());
if(prev[id]!=pos) {
if(prev[id]==-1) {
prev[id]=pos;
}else {
Cows[id]++;
prev[id]=pos;
}
}
}
f.close();
for(int i=0;i<cows;i++) {
total=total+Cows[i];
}
try{
System.out.println("TRYING TO WRITE");
PrintWriter pw=new PrintWriter(new BufferedWriter(new FileWriter("crossroad.out")));
pw.println(total);
pw.close();
}catch(IOException e) {
System.out.println("File MISSING");
}
}catch(Exception e) {
System.out.println("ERROR:"+e.getMessage());
System.exit(1);
}
}
}