-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathLargestRowColumn.java
More file actions
61 lines (56 loc) · 1.4 KB
/
LargestRowColumn.java
File metadata and controls
61 lines (56 loc) · 1.4 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
import java.util.Scanner;
public class LargestRowColumn {
public static int[][] input() {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c[][] = new int[a][b];
for (int x = 0; x < a; x++) {
for (int y = 0; y < b; y++) {
c[x][y] = sc.nextInt();
}
}
return c;
}
public static void largestRowColumn(int[][] a)
{
int sum=0;
String str="row"; int index=-1;
for (int x = 0; x < a[0].length; x++)
{
int s=0;
for (int y = 0; y < a.length; y++)
{
s+=a[x][y];
}
if(s>sum)
{
sum=s;
index=x;
}
}
for (int x = 0; x < a.length; x++)
{
int s=0;
for (int y = 0; y < a[0].length; y++)
{
s+=a[y][x];
}
if(s>sum)
{
sum=s;
str="column";
index=x;
}
}
System.out.println(str+" "+index+" "+sum);
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int x = 1; x <= t; x++) {
int a[][] = input();
largestRowColumn(a);
}
}
}