Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let sizeOfMatrix = gets().split(' ').map(Number);
- let row = sizeOfMatrix[0];
- let col = sizeOfMatrix[1];
- let matrix = [];
- for(let i = 0;i < row;i ++){
- let current = gets().split(' ');
- matrix[i] = [];
- for(let j = 0; j < col;j ++){
- matrix[i].push(current[j]);
- }
- }
- if(row == 0 || col == 0){
- lineResult = 0;
- columnResult = 0;
- firstDiagonal = 0;
- secondDiagonal = 0;
- }
- console.table(matrix);
- //check line.
- let lineResult = 1;
- for(let i = 0;i <= row - 1;i ++){
- let line = 1;
- for(let j = 0;j < col - 1;j ++){
- if(matrix[i][j] === matrix[i][j + 1]){
- line ++;
- if(line > lineResult){
- lineResult = line ;
- }
- }
- else{
- line = 1;
- }
- }
- }
- //check column.
- let columnResult = 1;
- for(let i = 0;i <= row - 1;i ++){
- let column = 1;
- for(let j = 0;j < col - 1; j ++){
- if(matrix[j][i] === matrix[j + 1][i]){
- column ++;
- if(column > columnResult){
- columnResult = column;
- }
- }
- else{
- column = 1;
- }
- }
- }
- //check first diagonal.
- let firstDiagonal = 1;
- for(let i = 0;i < row - 1;i++){
- let diagonal1 = 1;
- for(let j = 0;j < col - 1;j ++){
- if(matrix[i][j] === matrix[i + 1][j + 1]){
- diagonal1 ++;
- if(diagonal1 > firstDiagonal){
- firstDiagonal = diagonal1;
- }
- }
- else{
- diagonal1 = 1;
- }
- i ++;
- }
- }
- //check second diagonal.
- let secondDiagonal = 1;
- for(let i = 0;i < row - 1;i++){
- let diagonal2 = 1;
- for(let j = col - 1;j >= 1;j--){
- if(matrix[i][j] === matrix[i + 1][j - 1]){
- diagonal2 ++;
- if(diagonal2 > secondDiagonal){
- secondDiagonal = diagonal2;
- }
- }
- else{
- diagonal2 = 1;
- }
- i++;
- }
- }
- print(Math.max(lineResult,columnResult,firstDiagonal,secondDiagonal));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement