using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace ConsoleApplication1 { class Lab { List work = new List(); static double MinAbs; public Lab() { List work2 = new List((Program.read().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries))); foreach (string s in work2) { work.Add(double.Parse(s)); } MinAbs = CollMinAbs(); } public double CollMinAbs() { double min = work[0]; foreach (double z in work) { if (Math.Abs(z) < Math.Abs(min)) min = z; } return min; } public int FindIndexMinAbs() { return work.FindIndex(pred1); } private static bool pred1(double s) { if (s == MinAbs) return true; else return false; } public int FindFirstNegative() { int g = work.FindIndex(pred2); if (g > 0) return g; throw new Exception("Отрицательных элементов нет "); } private static bool pred2(double t) { if (t < 0) return true; else { return false; } } public double SummInterval(int t) { double summ = 0; for (int i = t; i < work.Count; ++i) { summ += Math.Abs(work[i]); } return summ; } public int delete = 0; public void DeleteInterval() { double a = Program.parse("\nВведите первую границу интервала "); double b = Program.parse("\nВведите вторую границу интервала "); int ihelp; int index = work.Count - 1; for (int i = 0; i < index - delete; ++i) { for (; work[i] >= a && work[i] <= b && i < work.Count - delete; ) { for (ihelp = i; ihelp < index; ++ihelp) work[ihelp] = work[ihelp + 1]; work[index - delete] = 0; ++delete; } } } public static void PrintList(Lab L) { foreach (double s in L.work) { Console.Write(s + " "); } } } class MyClass { int _a; int _b; public MyClass() { int a; int b; } public IEnumerator GetEnumerator() { return new MyEnumerator(); } } class MyEnumerator : IEnumerator { int _n = 0; public int Current { get { return _n++; } } public void Dispose() { } object System.Collections.IEnumerator.Current { get { throw new NotImplementedException(); } } public bool MoveNext() { return true; } public void Reset() { throw new NotImplementedException(); } } class Program { static void M() { } public static double parse(string message) { Console.Write(message); string buf = ""; double y = 1, x = 1; bool check; ; do { try { check = true; buf = Console.ReadLine(); x = double.Parse(buf); } catch { Console.ForegroundColor = ConsoleColor.Red; Console.Beep(300, 600); Console.WriteLine("Введённые данные неверны, повторите попытку"); Console.ForegroundColor = ConsoleColor.Gray; Console.Write(message); check = false; y++; if (y > 5) { for (int t = 3; t > 0; --t) { Console.Clear(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Программа закроется через {0} с. ", t); System.Threading.Thread.Sleep(1000); } Console.Clear(); Console.ForegroundColor = ConsoleColor.Gray; Environment.Exit(0); } } Console.ForegroundColor = ConsoleColor.Gray; } while (!check && y <= 5); return x; } public static string read() { string ret = ""; try { Console.Write("Введите адрес файла "); string s = Console.ReadLine(); ret = File.ReadAllText(s); } catch (Exception e) { Console.WriteLine(e.Message); Environment.Exit(0); } return ret; } static void Main(string[] args) { var list = new List>(); foreach (int item in new int[] { 1, 2, 3, 4, 5 }) { var n = item; Predicate m = delegate(int mn) { Console.WriteLine(n); return false; }; list.Add(m); } foreach (var item in list) { item(0); } Console.ReadKey(); try { Lab work = new Lab(); Lab.PrintList(work); Console.WriteLine(); Console.WriteLine("Номер минимального по модулю элемента " + work.FindIndexMinAbs()); Console.WriteLine("Сумма модулей элементов, согласно условию " + work.SummInterval(work.FindFirstNegative())); work.DeleteInterval(); Console.WriteLine("Удалено элементов " + work.delete); Lab.PrintList(work); } catch (Exception e) { Console.WriteLine(e.Message); } } } }