/* package whatever; // don't place package name! */
import java.util.* ;
import java.lang.* ;
import java.io.* ;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
{
int [ ] [ ] ia = new int [ 3 ] [ 3 ] ;
ia[ 0 ] [ 0 ] = 1 ;
ia[ 0 ] [ 1 ] = 1 ;
ia[ 0 ] [ 2 ] = 1 ;
ia[ 1 ] [ 0 ] = 4 ;
ia[ 1 ] [ 1 ] = 4 ;
ia[ 1 ] [ 2 ] = 2 ;
ia[ 2 ] [ 0 ] = 5 ;
ia[ 2 ] [ 1 ] = 6 ;
ia[ 2 ] [ 2 ] = 7 ;
findRepeats( ia, 9 ) ;
}
public static void findRepeats( int [ ] [ ] num, int size)
{
int findNum;
int total = 1 , row = 0 , col = 0 ;
int [ ] check = new int [ size] ;
while ( row < num.length && col < num[ 0 ] .length )
{
//Set to number
findNum = num[ row] [ col] ;
//Cycle array to set next number
if ( col < num[ 0 ] .length - 1 )
col++;
else
{
row++; //Go to next row if no more columns
col = 0 ; //Reset column number
}
//Loop through whole array to find repeats
for ( int i = row; i < num.length ; i++ )
{
for ( int j = col; j < num[ i] .length ; j++ )
{
if ( num[ i] [ j] == findNum) {
total++;
//Cycle array to set next number
if ( col < num[ 0 ] .length - 1 )
col++;
else
{
row++; //Go to next row if no more columns
col = 0 ; //Reset column number
}
if ( row < num.length - 1 && col < num[ 0 ] .length - 1 )
num[ i] [ j] = num[ row] [ col] ;
}
}
}
//Display total repeats
System .
out .
println ( "Number " + findNum
+ " appears " + total
+ " times." ) ; total = 1 ;
}
}
}
LyogcGFja2FnZSB3aGF0ZXZlcjsgLy8gZG9uJ3QgcGxhY2UgcGFja2FnZSBuYW1lISAqLwoKaW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CgovKiBOYW1lIG9mIHRoZSBjbGFzcyBoYXMgdG8gYmUgIk1haW4iIG9ubHkgaWYgdGhlIGNsYXNzIGlzIHB1YmxpYy4gK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ICAgICAgZm9yKGludCBpID0gcm93OyBpIDwgbnVtLmxlbmd0aDsgaSsrKQogICAgICAgIHsKICAgICAgICAgICAgZm9yKGludCBqID0gY29sOyBqIDwgbnVtW2ldLmxlbmd0aDsgaisrKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBpZihudW1baV1bal0gPT0gZmluZE51bSkgewogICAgICAgICAgICAgICAgICAgIHRvdGFsKys7CiAgICAgICAgICAgICAgICAgICAgIC8vQ3ljbGUgYXJyYXkgdG8gc2V0IG5leHQgbnVtYmVyCiAgICAgICAgICAgICAgICAgICAgICBpZihjb2wgPCBudW1bMF0ubGVuZ3RoLTEpCiAgICAgICAgICAgICAgICAgICAgICAgICAgY29sKys7CiAgICAgICAgICAgICAgICAgICAgICBlbHNlCiAgICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgIHJvdysrOyAgICAgIC8vR28gdG8gbmV4dCByb3cgaWYgbm8gbW9yZSBjb2x1bW5zCiAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbCA9IDA7ICAgIC8vUmVzZXQgY29sdW1uIG51bWJlcgogICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgaWYocm93IDwgbnVtLmxlbmd0aCAtIDEgJiYgY29sIDwgbnVtWzBdLmxlbmd0aCAtMSkKICAgICAgICAgICAgICAgICAgICAgICAgIG51bVtpXVtqXSA9IG51bVtyb3ddW2NvbF07CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICB9CgoKICAgICAgICAvL0Rpc3BsYXkgdG90YWwgcmVwZWF0cwogICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbigiTnVtYmVyICIgKyBmaW5kTnVtICsgIiBhcHBlYXJzICIgKyB0b3RhbCArICIgdGltZXMuIik7CiAgICAgICAgdG90YWwgPSAxOwogICAgfQp9Cn0=