public string SolveIt() { int length = Convert.ToInt32(_reader.ReadLine()); string input = _reader.ReadLine(); int factor = Convert.ToInt32(_reader.ReadLine()); var inputChars = input.ToCharArray(); for (int i = 0; i < length; i++) { char c = inputChars[i]; if (_punctuation.Contains(c) || _numbers.Contains(c)) { continue; } int currentPos = Char.IsLower(c) ? Array.IndexOf(_lowerCaseAlphabet, c) : Array.IndexOf(_upperCaseAlphabet, c); int newPos = currentPos + factor; if (newPos > _lowerCaseAlphabet.Length - 1) { newPos = newPos % _lowerCaseAlphabet.Length; } inputChars[i] = Char.IsLower(c) ? _lowerCaseAlphabet[newPos] : _upperCaseAlphabet[newPos]; } return(new string(inputChars)); }
public bool TryReadInputs([NotNullWhen(true)] out Inputs?inputs) { inputs = null; int expectedInstructions = _reader.ReadLine().AsInt(); var initialTileCoordinates = _reader.ReadLine(); if (expectedInstructions >= MaxInstructions) { return(false); } var instructions = new List <Instruction>(); for (int i = 1; i <= expectedInstructions; i++) { var str = _reader.ReadLine(); if (Instruction.TryParse(str, out var instruction) && instruction.Distance < MaxDistance) { instructions.Add(instruction); } } if (Tile.TryParse(initialTileCoordinates, out var initialTile) && initialTile.X.IsBetween(MinX, MaxX) && initialTile.Y.IsBetween(MinY, MaxY)) { inputs = new Inputs(initialTile, instructions); return(true); } return(false); }
public MarsMap GetMarsMap() { string mapSizeLine = _consoleReader.ReadLine(); if (mapSizeLine.Length != 3 || mapSizeLine[1] != ' ') { throw new InputFormatException(mapSizeLine); } var point = GetMarsPoint(mapSizeLine); return(new MarsMap(point)); }
public IList <ICommand> ReadCommands() { var commands = new List <ICommand>(); var currentLine = consoleReader.ReadLine(); while (!string.IsNullOrEmpty(currentLine)) { var currentCommand = Command.Parse(currentLine); commands.Add(currentCommand); currentLine = consoleReader.ReadLine(); } return(commands); }
public Option <string> GetValidatedValue(IUserInputDescription variable, IEnumerable <IValidation> requesterValidations) { _consoleWriter.WriteLine(); _consoleWriter.Write($"{variable.VariableName}: "); return(Validate(variable, requesterValidations)(_consoleReader.ReadLine())); }
public int SolveIt() { string[] actualReturnDate = _reader.ReadLine().Split(' '); string[] expectedReturnDate = _reader.ReadLine().Split(' '); int actualDay = Convert.ToInt32(actualReturnDate[0]); int expectedDay = Convert.ToInt32(expectedReturnDate[0]); int actualMonth = Convert.ToInt32(actualReturnDate[1]); int expectedMonth = Convert.ToInt32(expectedReturnDate[1]); int actualYear = Convert.ToInt32(actualReturnDate[2]); int expectedYear = Convert.ToInt32(expectedReturnDate[2]); int fine; DateTime actual = new DateTime(actualYear, actualMonth, actualDay); DateTime expected = new DateTime(expectedYear, expectedMonth, expectedDay); if (actual.Equals(expected) || actual < expected) { return(0); } int daysDiff = Math.Abs((expected - actual).Days); int yearsDiff = Math.Abs(expected.Year - actual.Year); if (yearsDiff > 0) { return(10000); } if (daysDiff > 31) { int monthsDiff = Math.Abs(expected.Month - actual.Month); fine = monthsDiff * 500; } else { fine = daysDiff * 15; } return(fine); }
public static int getCount(IConsoleReader reader) //ввод количества реквестов в топе { int count = 0; Console.WriteLine("Введите число, ограничивающее топ запросов"); if (!int.TryParse(reader.ReadLine(), out count) || count <= 0) { Console.WriteLine("Введено некорректное число, взято число по умолчанию (5)"); count = 5; } return(count); }
public void Run() { string input = reader.ReadLine(); GameController gameController = new GameController(writer); while (!input.Equals(poolbackCommand)) { try { gameController.GiveInputToGameController(input); } catch (ArgumentException arg) { writer.AppendLine(arg.Message); } input = this.reader.ReadLine(); } gameController.RequestResult(); this.writer.WriteLineAll(); }