Masai Competitions
Description
Masai is organizing a sports fest that is going to run for N days, and everyday M people are going to participate in it. Each player is having some power rating P. The person with higher value of P, wins everyday. You are given the powers of all the people participating everyday. You have to find the winner for everyday, and print their power in the form of a list. Refer the sample I/O for better understanding.
Note: Two people may have the same power.
Input
The first line of the input contains T, the number of test cases.
The first line of each test case contains the values of N and M.
The next lines contain M integers, denoting the powers of all the players participating on a given day.
1 <= T <= 10
1 <= N, M <= 100
1 <= A[i][j] <= 100
Output
Print the power rating P, of all the winners for everyday, on a single line, for each test case.
Hint
In the first sample test case, the winner of day 1, is with person with power 4, while the winner on second day is person with power 8, while the winner on day 3 is person with power 12.
In the second sample test case, on day 1 two people have power 7, so any of them can be the winner. Therefore, the output will be 7 for day 1, for day 2 it will be 10, and for day 3 it will be 3.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int steps = sc.nextInt();
for (int t = 0;t<steps;t++){
int row = sc.nextInt();
int col = sc.nextInt();
//making and feeding array
int[][] array= new int[row][col];
int[] ans = new int[row];
for (int i = 0;i<row;i++){
int feed = -1;
for (int j = 0;j<col;j++){
array[i][j]= sc.nextInt();
if (feed<array[i][j]){
feed=array[i][j];
}
}ans[i]=feed;
}//making & feeded array compleately
for (int j = 0;j<row;j++){
System.out.print(ans[j]+" ");
}
// for (int i = 0;i<row;i++){
// for (int j = 0;j<col;j++){
// array[i][j]= sc.nextInt();
// }
// }
System.out.println();
}
}
}
No comments:
Post a Comment