-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPolygonCounter.java
More file actions
46 lines (37 loc) · 1.01 KB
/
PolygonCounter.java
File metadata and controls
46 lines (37 loc) · 1.01 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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class PolygonCounter {
public static void main(String[] args) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {
String s = null;
int sq = 0;
int rect = 0;
int poly = 0;
while (true) {
s = br.readLine();
if (s == null || s.equals("")) {
break;
}
String[] sideStrings = s.split(" ");
int[] sides = new int[sideStrings.length];
for (int i = 0; i < sideStrings.length; i++) {
sides[i] = Integer.parseInt(sideStrings[i]);
}
if (sides[0] <= 0 || sides[1] <= 0 || sides[2] <= 0 || sides[3] <= 0) {
poly++;
} else if (sides[0] == sides[1] && sides[1] == sides[2] && sides[2] == sides[3]) {
sq++;
} else if (sides[0] == sides[2] && sides[1] == sides[3]) {
rect++;
} else {
poly++;
}
}
System.out.println(sq + " " + rect + " " + poly);
} catch (IOException e) {
e.printStackTrace();
}
}
}