#include<stdio.h>
int main(){
int ar[100][100];
int R, C, r, c;
scanf("%d %d", &R, &C);
int occurR[10000], occurC[10000], occurSize=0;
for(r=0; r<R; r++){
for(c=0; c<C; c++){
scanf("%d", &ar[r][c]);
}
}
int max=ar[0][0];
for(r=0; r<R; r++){
for(c=0; c<C; c++){
if(max<ar[r][c]){
max=ar[r][c];
occurSize=0;
}
if(max==ar[r][c]){
occurR[occurSize]=r;
occurC[occurSize]=c;
occurSize++;
}
}
}
int i;
printf("Max is %d\nAnd occurrences are: ",max);
for(i=0; i<occurSize;i++){
printf("(%d,%d) ",occurR[i], occurC[i]);
}
return 0;
}
Sample Input:
4 5
10 20 10 30 30
15 25 30 35 15
20 35 10 15 35
40 30 25 40 40
Output tracing:
R=4, C=5
After Input-->
max = ar[0][0] = 10
occurR-->empty, occurC-->empty, occurSize=0
For(r=0):
----------------------
----------------------
c=0: max==a[0][0]-->true
So, occurR:{0}, occurC:{0}, occurSize=1
----------------------
c=1: max<=a[0][1]-->true
So, max=20, occurSize=1, occurR:{0}, occurC:{1}
-----------------------
c=3: max<=a[0][3]-->true
So, max=30, occurSize=1, occurR:{0}, occurC:{3}
-----------------------
c=4: max==a[0][4]-->true
So, max=30, occurSize=2, occurR:{0,0}, occurC:{3, 4}
------------------------
For (r=1)
-----------------------
-----------------------
c=2: max==a[1][2]-->true
So, max=30, occurSize=3, occurR:{0,0, 1}, occurC:{3, 4, 2}
-----------------------
c=3: max<=a[1][3]-->true
So, max=35, occurSize=1, occurR:{1}, occurC:{3}
-----------------------
####Complete the rest in similar fashion####
Sample Output:
Max is 40
And occurrences are: (3,0) (3,3) (3,4)