-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathCensus.java
More file actions
41 lines (38 loc) · 1.32 KB
/
Copy pathCensus.java
File metadata and controls
41 lines (38 loc) · 1.32 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
package census;
import java.io.*;
import java.util.*;
public class Census {
private static ArrayList<Integer> data = new ArrayList<>();
private static int oldManNumber = -1;
private static int manAge = 0;
private static void dataValidation(){ //
int j = 0; // Счетчик номера жильца
for (int i = 0; i < data.size(); i++){
if(data.get(i) != 0 && i % 2 == 1){
j++;
}
if(i % 2 == 1 && data.get(i+1) == 1 && i+1 < data.size()){ // Проверка возраста мужчины
if(data.get(i) > manAge){
manAge = data.get(i);
oldManNumber = j;
}
}
}
}
public static void main(String[] args) 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()){
data.add(Integer.valueOf(st.nextToken()));
}
}
dataValidation();
FileWriter fileOut = new FileWriter("output.txt");
fileOut.write(String.valueOf(oldManNumber));
fileOut.close();
}
}