Created
November 15, 2015 02:42
-
-
Save komkanit/aea44ca4e9380725825a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| class Matrix | |
| { | |
| static string [,] map = new string[100,100]; | |
| static int n,m,lenp = 0; | |
| static int[] px = new int[100]; | |
| static int[] py = new int[100]; | |
| public static void Main() | |
| { | |
| Console.Write("Input size y: "); | |
| n = int.Parse(Console.ReadLine()); | |
| Console.Write("Input size x: "); | |
| m = int.Parse(Console.ReadLine()); | |
| int i,j,count,max = 0,lenm = 0,c; | |
| int[] mx = new int[100]; | |
| int[] my = new int[100]; | |
| for(i=0 ; i<n ; i++) | |
| { | |
| string str = Console.ReadLine(); | |
| string[] s = str.Split(' '); | |
| for(j=0 ; j<m ; j++) | |
| map[i,j] = s[j]; | |
| } | |
| for(i=0 ; i<n ; i++) | |
| { | |
| for(j=0 ; j<m ; j++) | |
| { | |
| Check(i,j); | |
| lenp--; | |
| while(lenp >= 0) | |
| { | |
| count = 0; | |
| while(i+py[lenp]>=0 && i+py[lenp]<n && j+px[lenp]>=0 && j+px[lenp]<m && map[i,j].Equals(map[i+py[lenp],j+px[lenp]])) | |
| { | |
| //Console.WriteLine(py[lenp] + " " + px[lenp]); | |
| count++; | |
| if(px[lenp] > 0) | |
| px[lenp]++; | |
| else if(px[lenp] < 0) | |
| px[lenp]--; | |
| if(py[lenp] > 0) | |
| py[lenp]++; | |
| else if(py[lenp] < 0) | |
| py[lenp]--; | |
| //Console.Write("111"); | |
| } | |
| if(max < count){ | |
| max = count; | |
| lenm = 0; | |
| mx[lenm] = j; | |
| my[lenm] = i; | |
| lenm++; | |
| } | |
| else if(max == count) | |
| { | |
| mx[lenm] = j; | |
| my[lenm] = i; | |
| lenm++; | |
| } | |
| lenp--; | |
| } | |
| lenp = 0; | |
| } | |
| } | |
| for(i=0 ; i<lenm ; i++) | |
| { | |
| c = 0; | |
| for(j=0 ; j<i ; j++) | |
| { | |
| if(map[my[i],mx[i]].Equals(map[my[j],mx[j]])){ | |
| c = 1; | |
| } | |
| } | |
| if(c == 0){ | |
| for(j=0 ; j<=max ; j++) | |
| Console.Write(map[my[i],mx[i]]); | |
| Console.WriteLine(" "); | |
| } | |
| } | |
| } | |
| static void Check(int y,int x) | |
| { | |
| if(x+1 < m && map[y,x].Equals(map[y,x+1])){ | |
| px[lenp] = 1; | |
| py[lenp] = 0; | |
| lenp++; | |
| } | |
| if(y+1 < n && map[y,x].Equals(map[y+1,x])){ | |
| px[lenp] = 0; | |
| py[lenp] = 1; | |
| lenp++; | |
| } | |
| if(x+1 < m && y+1 < n && map[y,x].Equals(map[y+1,x+1])){ | |
| px[lenp] = 1; | |
| py[lenp] = 1; | |
| lenp++; | |
| } | |
| if(x-1 > -1 && y+1 < n && map[y,x].Equals(map[y+1,x-1])){ | |
| px[lenp] = -1; | |
| py[lenp] = 1; | |
| lenp++; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment