Skip to content

Instantly share code, notes, and snippets.

@Ph47
Created January 13, 2015 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ph47/ae69edf0088ac215d225 to your computer and use it in GitHub Desktop.
Save Ph47/ae69edf0088ac215d225 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApp1
{
public class Program
{
public void Main(string[] args)
{
// Инициализация данных
int[][] A = new int [10][];
Random r = new Random();
for (int i = 0; i < A.Length; i++)
{
A[i] = new int[15];
A[i] = A[i].Select(j => r.Next()).ToArray();
}
// Вызов заветной функции и присвоение результатов
KeyValuePair<int[], int[]> MS = MyCopypastedSolution(A);
int[] M = MS.Key;
int[] S = MS.Value;
// Вывод данных
Console.WriteLine("M:");
Console.WriteLine(string.Join(",", M));
Console.WriteLine("S:");
Console.WriteLine(string.Join(",", S));
Console.ReadLine();
}
private KeyValuePair<int[], int[]> MyCopypastedSolution(int[][] A)
{
// Инициализация массивов результата
KeyValuePair<int[], int[]> result =
new KeyValuePair<int[], int[]>(new int[A.Length], new int[A.Length]);
// Перебор строк
for (int i = 0; i < A.GetLength(0); i++)
{
// Минимальное значение
result.Key[i] = A[i].Min();
// Сумма индексов
result.Value[i] = A[i].ToList().IndexOf(result.Key[i]) + i;
}
return result;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment