Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using System.Linq;
- using System.Text.RegularExpressions;
- namespace Rextester
- {
- public class Program
- {
- public static void Sort(int[,] arr)
- {
- for (int i = 0; i < arr.GetLength(0); i++)
- {
- for (int j = arr.GetLength(1) - 1; j > 0; j--)
- {
- for (int k = 0; k < j; k++) {
- if (arr[i, k] > arr[i, k + 1]) {
- int myTemp = arr[i, k];
- arr[i, k] = arr[i, k + 1];
- arr[i, k + 1] = myTemp;
- }
- }
- }
- }
- }
- public static List<int> GetSolution(int[,] P)
- {
- var Q = new int[P.GetLength(0), P.GetLength(1)];
- for (int i = 0; i < P.GetLength(0); i += 2)
- {
- for (int j = 0; j < P.GetLength(1); j++)
- {
- Q[i,j] = P[i,j];
- }
- }
- Sort(Q);
- var arr = new int[Q.GetLength(0) * Q.GetLength(1)];
- int arrIndex = 0;
- for (int i = 0; i < Q.GetLength(0); i++)
- {
- for (int j = 0; j < Q.GetLength(1); j++)
- {
- arr[arrIndex] = Q[i,j];
- arrIndex++;
- }
- }
- var list = new List<int>();
- for (int i = 0; i < arr.Length; i++)
- {
- if (arr[i] == i)
- {
- list.Add(i);
- }
- }
- return list;
- }
- public static void Main(String[] args) {
- var P = new int[,]
- {
- {
- 1,1,1,2
- },
- {
- 2,3,3,4
- },
- {
- 4,4,4,4
- },
- {
- 1,2,3,1
- }
- };
- var result = GetSolution(P);
- var resStr = String.Join(", ", result);
- Console.WriteLine(resStr);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement