-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1243.java
More file actions
46 lines (41 loc) · 1.2 KB
/
1243.java
File metadata and controls
46 lines (41 loc) · 1.2 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.IOException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
Scanner leitor = new Scanner(System.in);
while (leitor.hasNext()) {
String linha = readLine(leitor);
String[] palavras = linha.split(" ");
int countPalavras = 0;
int tamanhoPalavras = 0;
for (String palavra : palavras) {
boolean palavraValida = true;
for (int i = 0; i < palavra.length(); i++) {
char c = palavra.charAt(i);
if (!Character.isAlphabetic(c) && !(c == '.' && i + 1 == palavra.length())) {
palavraValida = false;
break;
}
}
if (palavraValida) {
countPalavras++;
tamanhoPalavras += palavra.replace(".", "").length();
}
}
if (countPalavras == 0 || tamanhoPalavras == 0) {
System.out.println(250);
} else {
int media = tamanhoPalavras / countPalavras;
if (media <= 3) System.out.println(250 );
else if (media <= 5) System.out.println(500 );
else System.out.println(1000);
}
}
}
public static String readLine(Scanner leitor) {
String line = leitor.nextLine();
while (line.isEmpty())
line = leitor.nextLine();
return line;
}
}