Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text;
- namespace PasswordReset
- {
- class Program
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- StringBuilder oldSbPassword = new StringBuilder(input);
- StringBuilder newSbPassword = new StringBuilder();
- string command = string.Empty;
- while ((command = Console.ReadLine()) != "Done")
- {
- string[] commandArray = command.Split();
- if (commandArray[0] == "TakeOdd")
- {
- for (int i = 0; i <= oldSbPassword.Length - 1; i++)
- {
- if (i % 2 != 0)
- {
- newSbPassword.Append(oldSbPassword[i]);
- }
- }
- Console.WriteLine(newSbPassword);
- oldSbPassword = newSbPassword;
- }
- else if (commandArray[0] == "Cut")
- {
- int index = int.Parse(commandArray[1]);
- int validCurrentIndex = Math.Max(0, index);
- int validIndex = Math.Min(oldSbPassword.Length - 1, validCurrentIndex);
- int length = int.Parse(commandArray[2]);
- int validLength = Math.Max(0, length);
- int validCurrentLength = Math.Min(length, (oldSbPassword.Length - validCurrentIndex));
- oldSbPassword.Remove(validCurrentIndex, validCurrentLength);
- Console.WriteLine(oldSbPassword);
- }
- else if (commandArray[0] == "Substitute")
- {
- string substring = commandArray[1];
- string substitute = commandArray[2];
- if (oldSbPassword.ToString().Contains(substring) && substitute != substring)
- {
- oldSbPassword.Replace(substring, substitute);
- Console.WriteLine(oldSbPassword);
- }
- else if (oldSbPassword.ToString().Contains(substring) && substitute == substring)
- {
- Console.WriteLine("Nothing to replace!");
- }
- else if (oldSbPassword.ToString().Contains(substring) == false)
- {
- Console.WriteLine("Nothing to replace!");
- }
- }
- }
- Console.WriteLine($"Your password is: {oldSbPassword}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement