Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [STAThread]
- public static void Main()
- {
- Console.Write("Введите элементы массива: ");
- int[] array = ReadArray(true);
- if (array == null)
- {
- Console.WriteLine("\nНе удалось считать массив.\nНажмите любую клавишу.");
- Console.ReadKey(true);
- return;
- }
- ReverseArray(ref array);
- Console.Write("Обратный массив: ");
- foreach (int i in array)
- {
- Console.Write("{0} ", i);
- }
- Console.WriteLine("\nСумма значений после минимального элемента: {0}\nНажмите любую клавишу.", SummarizeAfterMin(array));
- Console.ReadKey(true);
- }
- private static int[] ReadArray(bool fromFile = false)
- {
- string array;
- if (fromFile)
- {
- OpenFileDialog fileDialog = new OpenFileDialog();
- DialogResult result=fileDialog.ShowDialog();
- if (result == DialogResult.Yes || result == DialogResult.OK)
- {
- if (fileDialog.CheckFileExists && !string.IsNullOrEmpty(fileDialog.SafeFileName))
- {
- array = File.ReadAllLines(fileDialog.FileName).FirstOrDefault();
- if (string.IsNullOrEmpty(array))
- return null;
- }
- else
- return null;
- }
- else
- return null;
- }
- else
- {
- array = Console.ReadLine();
- }
- return array?.Split(new[] {',', ' ', '\t'}, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
- }
- private static void ReverseArray(ref int[] array)
- {
- array = array.Reverse().ToArray();
- }
- private static int SummarizeAfterMin(int[] array)
- {
- int index = Array.IndexOf(array, array.Min());
- int sum = 0;
- for (; index < array.Length; index++)
- sum += array[index];
- return sum;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement