-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathRoad.java
More file actions
35 lines (33 loc) · 1.02 KB
/
Copy pathRoad.java
File metadata and controls
35 lines (33 loc) · 1.02 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
package road;
import java.util.*;
import java.io.*;
public class Road {
private static ArrayList<Integer> number = new ArrayList<>();
private static void getData() throws IOException{
FileReader file = new FileReader("input.txt");
Scanner sc = new Scanner(file);
String str;
while (sc.hasNextLine()){
str = sc.nextLine();
StringTokenizer st = new StringTokenizer(str, " ");
while (st.hasMoreTokens()){
number.add(Integer.valueOf(st.nextToken()));
}
}
}
public static void main(String[] argv) throws IOException{
getData();
int roadCount = 0;
for(int i = 0; i < number.size(); i++){
if(i != 0){
if(number.get(i) == 1){
roadCount++;
}
}
}
roadCount = roadCount / 2;
PrintWriter pw = new PrintWriter(new File("output.txt"));
pw.print(String.valueOf(roadCount));
pw.close();
}
}