Teacher Weng Kai once designed a Java challenge game called "Mouse Loves Rice" (perhaps because his nickname is "Fat Fat Mouse"). Each player uses Java code to control a mouse. The goal is to eat as much rice as possible to turn himself into a fat mouse. The fattest one is the champion.
Because the game time cannot be too long, we divide the players into N groups, with M mice in each group competing in the same field, and then directly select the fattest champion Fatty Rat from the N group champions. Now please write a program to get the champion's weight.
Input format:
The input gives 2 positive integers in the first line: N (≤100) is the number of groups, and M (≤10) is the number of players in each group. Then there are N lines, each line gives the final weight of a group of M mice controlled by the player, all of which are non-negative integers not exceeding 104. Separate numbers with spaces.
Output format:
First, output the weight of each group champion in sequence on the first line. The numbers are separated by 1 space. There should be no extra spaces at the beginning and end of the line. Then the weight of the champion Fat Rat is output in the second line.
Input example:
3 5
62 53 88 72 81
12 31 9 0 2
91 42 39 6 48
Output sample:
88 31 91
91
Code length limit
16 KB
time limit
400 ms
memory limit
64 MB
Code:
#include <iostream>
using namespace std;
int main(){
int N,M,i,j,k=0;
int maximum[101];
int weight,temp=-999,max;
cin>>N>>M;
for(i=0;i<N;i++){
temp=-999;
for(j=0;j<M;j++){
cin>>weight;
if(weight>temp) temp=weight;
}
maximum[k++]=temp;
}
cout<<maximum[0];
for(i=1;i<N;i++){
cout<<" "<<maximum[i];
}
cout<<endl;
max=maximum[0];
for(i=0;i<N;i++){
if(maximum[i]>max) max=maximum[i];
}
cout<<max;
return 0;
}