Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net;
- using System.Reflection;
- using System.Runtime.CompilerServices;
- using System.Security.Cryptography.X509Certificates;
- namespace ConsoleApplication
- {
- class Program
- {
- private static List<Time> timelist = new List<Time>();
- private static bool format = false;
- static void Main(string[] args)
- {
- while (true)
- {
- var commandLine = Console.ReadLine();
- var arguments = commandLine.Split(' ');
- var command = arguments[0];
- if (command.Length == 0)
- continue;
- var method = typeof(Program).GetMethod(command);
- if (method == null)
- {
- Console.WriteLine("Such method does not exist");
- Console.WriteLine("Type \"help\" to get help\n");
- continue;
- }
- method.Invoke(null, new object[]{SubArray(arguments, 1)});
- }
- }
- public static T[] SubArray<T>(T[] data, int index)
- {
- var result = new T[data.Length-1];
- Array.Copy(data, index, result, 0, data.Length-1);
- return result;
- }
- public static void Help(object obj)
- {
- Console.WriteLine(
- "1) help – вывод списка поддерживаемых команд\n" +
- "2) add – добавить элемент\n" +
- "3) remove all/n – удалить элемент n либо очистить весь список\n" +
- "4) list [i] [n] – вывести на печать т элементов, начиная с i\n" +
- "5) sort – отсортировать по заданному алгоритму (см. варианты)\n" +
- "6) доп. команда (см. варианты)\n" +
- "7) exit и quit – завершение работы\n"
- );
- }
- public static void Quit(object obj)
- {
- Environment.Exit(0);
- }
- public static void Exit(object obj)
- {
- Environment.Exit(0);
- }
- public static void Add(object obj)
- {
- var parameters = (string[]) obj;
- var t = double.Parse(parameters[0]);
- var x = double.Parse(parameters[1]);
- timelist.Add(new Time(t, x));
- }
- public static void Remove(object obj)
- {
- var parameters = (string[]) obj;
- if (parameters[0] == "all")
- {
- timelist.Clear();
- }
- else
- {
- timelist.RemoveAt(int.Parse(parameters[0]) - 1);
- }
- }
- public static void List(object obj)
- {
- var parameters = (string[]) obj;
- switch (parameters.Length)
- {
- case 0:
- foreach (var timeItem in timelist)
- {
- Console.WriteLine(timeItem);
- }
- break;
- case 1:
- var begin = int.Parse(parameters[0]) - 1;
- for (var i = begin; i < timelist.Count; ++i)
- {
- Console.WriteLine(timelist.ElementAt(i));
- }
- break;
- case 2:
- begin = int.Parse(parameters[0]) - 1;
- var end = int.Parse(parameters[1]) - 1;
- for (var i = 0; i < end; ++i)
- {
- if (begin + i >= timelist.Count)
- {
- break;
- }
- Console.WriteLine(timelist.ElementAt(begin + i));
- }
- break;
- }
- }
- public static void Sort(object obj)
- {
- timelist.Sort();
- }
- public static void CountTrendTriangle(object obj)
- {
- }
- public static void Format(object obj)
- {
- var fileFormat = (string) obj;
- switch (fileFormat)
- {
- case "short":
- format = false;
- break;
- case "full":
- format = true;
- break;
- default:
- Console.WriteLine(string.Format("There's no such an option: {}", fileFormat));
- break;
- }
- }
- public static void Save(object obj)
- {
- var filepath = (string) obj;
- System.IO.Path.IsPathRooted(filepath);
- }
- }
- internal class Time : IComparable<Time>
- {
- private readonly double t;
- private readonly double x;
- public Time(double t, double x)
- {
- this.t = t;
- this.x = x;
- }
- public override string ToString()
- {
- return string.Format("({0}, {1})", t, x);
- }
- public int CompareTo(Time other)
- {
- if (ReferenceEquals(this, other)) return 0;
- if (ReferenceEquals(null, other)) return 1;
- var tComparison = t.CompareTo(other.t);
- return tComparison != 0 ? tComparison : x.CompareTo(other.x);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment