Advertisement
cap7ainjack

Matrix_Sequence

Sep 22nd, 2015
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.15 KB | None | 0 0
  1. string[,] matrix =
  2. {
  3. { "ha", "hihi", "ho", "hi"},
  4. {"fo", "ha", "hi", "xx" },
  5. {"xxx", "ho", "ha", "xx" }
  6. };
  7.  
  8. Dictionary<string,int> allWords = new Dictionary<string, int>();
  9.  
  10.  
  11. // create 2x2 platform
  12.  
  13. int platformRows = 2;
  14. int platformCols = 2;
  15.  
  16. for (int row = 0; row <= matrix.GetLength(0) - platformRows ; row++)
  17. {
  18. for (int col = 0; col <= matrix.GetLength(1) - platformCols; col++)
  19. {
  20.  
  21. // 1 they are 6 if`s for each platform position, checking all the four elements if there are equals between them
  22. if (matrix[row,col] == matrix[row,col+1])
  23. {
  24. string curWord = matrix[row, col];
  25. if (!(allWords.ContainsKey(curWord)))
  26. {
  27. allWords.Add(curWord,1);
  28. }
  29. else
  30. {
  31. allWords[curWord]++;
  32. }
  33. }
  34.  
  35. //2
  36. if (matrix[row, col] == matrix[row+1, col])
  37. {
  38. string curWord = matrix[row, col];
  39. if (!(allWords.ContainsKey(curWord)))
  40. {
  41. allWords.Add(curWord, 1);
  42. }
  43. else
  44. {
  45. allWords[curWord]++;
  46. }
  47. }
  48.  
  49. //3
  50. if (matrix[row, col] == matrix[row + 1, col+1])
  51. {
  52. string curWord = matrix[row, col];
  53. if (!(allWords.ContainsKey(curWord)))
  54. {
  55. allWords.Add(curWord, 1);
  56. }
  57. else
  58. {
  59. allWords[curWord]++;
  60. }
  61. }
  62.  
  63.  
  64. //4
  65. if (matrix[row+1, col] == matrix[row, col+1])
  66. {
  67. string curWord = matrix[row+1, col];
  68. if (!(allWords.ContainsKey(curWord)))
  69. {
  70. allWords.Add(curWord, 1);
  71. }
  72. else
  73. {
  74. allWords[curWord]++;
  75. }
  76. }
  77.  
  78. //5
  79. if (matrix[row + 1, col] == matrix[row+1, col + 1])
  80. {
  81. string curWord = matrix[row+1, col];
  82. if (!(allWords.ContainsKey(curWord)))
  83. {
  84. allWords.Add(curWord, 1);
  85. }
  86. else
  87. {
  88. allWords[curWord]++;
  89. }
  90. }
  91.  
  92. //6
  93. if (matrix[row, col+1] == matrix[row + 1, col + 1])
  94. {
  95. string curWord = matrix[row, col+1];
  96. if (!(allWords.ContainsKey(curWord)))
  97. {
  98. allWords.Add(curWord, 1);
  99. }
  100. else
  101. {
  102. allWords[curWord]++;
  103. }
  104. }
  105.  
  106. }
  107. }
  108.  
  109. //print the result
  110.  
  111.  
  112. var biggestSeq = allWords.Aggregate((l, r) => l.Value > r.Value ? l : r).Key;
  113. var biggestSeqCount = allWords.Aggregate((l, r) => l.Value > r.Value ? l : r).Value;
  114.  
  115. // Console.WriteLine("{0}, {1}",biggestSeq,biggestSeqCount);
  116.  
  117. for (int i = 0; i < biggestSeqCount+1; i++)
  118. {
  119. Console.Write("{0}, ", biggestSeq);
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement