-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathBasketball.java
More file actions
38 lines (36 loc) · 1.35 KB
/
Copy pathBasketball.java
File metadata and controls
38 lines (36 loc) · 1.35 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
package basketball;
import java.util.*;
import java.io.*;
public class Basketball {
public static void main(String[] args) throws IOException {
ArrayList<String> line = new ArrayList<>();
ArrayList<Integer> score = new ArrayList<>();
int a = 0, b = 0;
String winner;
String str;
FileReader file = new FileReader("input.txt"); // Считывание данных из файла
Scanner sc = new Scanner(file);
while (sc.hasNextLine()){
str = sc.nextLine();
line.add(str);
}
for(String i : line){ // Записать все очки в одну коллекцию
StringTokenizer st = new StringTokenizer(i, " ");
while(st.hasMoreTokens()){
score.add(Integer.valueOf(st.nextToken()));
}
}
for(int j = 0; j < score.size(); j++){ // Подсчет количества очков для каждой из команд
if((j+1)%2 == 1){
a += score.get(j);
}else{
b += score.get(j);
}
}
winner = (a > b) ? "1" : // Какая команда победила
(b > a) ? "2" : "DRAW";
FileWriter fileOut = new FileWriter("output.txt");
fileOut.write(winner);
fileOut.close();
}
}