Repository navigation
Expand file tree
/
Copy pathQ20.java
More file actions
62 lines (50 loc) · 1.78 KB
/
Copy pathQ20.java
File metadata and controls
62 lines (50 loc) · 1.78 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import java.util.Scanner;
public class Q20 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int l = sc.nextInt();
int c = sc.nextInt();
int[][] matriz = new int[l][c];
for (int i = 0; i < l; i++) {
for (int j = 0; j < c; j++) {
matriz[i][j] = sc.nextInt();
}
}
int k = sc.nextInt();
int maiorComprimento = 0;
int linhaSeq = -1;
int indiceInicial = -1;
int indiceFinal = -1;
for (int i = 0; i < l; i++) {
int comprimento = 0;
int inicio = 0;
for (int j = 0; j < c; j++) {
if (matriz[i][j] > k) {
if (comprimento == 0) {
inicio = j;
}
comprimento++;
} else {
if (comprimento > maiorComprimento) {
maiorComprimento = comprimento;
linhaSeq = i;
indiceInicial = inicio;
indiceFinal = j - 1;
}
comprimento = 0;
}
}
if (comprimento > maiorComprimento) {
maiorComprimento = comprimento;
linhaSeq = i;
indiceInicial = inicio;
indiceFinal = c - 1;
}
}
System.out.println("Maior sequencia acima de " + k + ": " + maiorComprimento);
System.out.println("Linha da sequencia: " + linhaSeq);
System.out.println("Indice inicial: " + indiceInicial);
System.out.println("Indice final: " + indiceFinal);
sc.close();
}
}