-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatran.java
39 lines (37 loc) · 1.21 KB
/
matran.java
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
package test;
import java.util.*;
import java.io.*;
public class matran {
public static void main(String args[]) throws FileNotFoundException{
Scanner in = new Scanner(new File("MATRIX.in"));
int t = Integer.parseInt(in.nextLine());
while(t-- >0){
int n = in.nextInt();
int m = in.nextInt();
int x = in.nextInt();
int[][] a = new int[n+3][m+3];
ArrayList<Integer> v = new ArrayList<>();
for(int i = 1; i <= n; i++){
for(int j = 1;j <= m; j++){
a[i][j] = in.nextInt();
if(j == x){
v.add(a[i][j]);
}
}
}
Collections.sort(v);
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
if(j != x){
System.out.printf("%d ",a[i][j]);
}
else{
System.out.printf("%d ",v.get(0));
v.remove(0);
}
}
System.out.println("");
}
}
}
}