Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text;
- using System.Text.RegularExpressions;
- namespace PasswordReset_ExamApril2020
- {
- class Program
- {
- static void Main(string[] args)
- {
- string password = Console.ReadLine();
- StringBuilder newRawPassword = new StringBuilder();
- while (true)
- {
- string[] command = Console.ReadLine().Split();
- if (command[0] == "Done")
- {
- break;
- }
- if (command[0] == "TakeOdd")
- {
- for (int i = 1; i < password.Length; i +=2)
- {
- newRawPassword.Append(password[i]);
- }
- Console.WriteLine(newRawPassword);
- }
- else if (command[0] == "Cut")
- {
- string cut = newRawPassword.ToString().Substring(int.Parse(command[1]), int.Parse(command[2]));
- int index = newRawPassword.ToString().IndexOf(cut);
- newRawPassword = newRawPassword.Remove(index, cut.Length);
- Console.WriteLine(newRawPassword);
- }
- else if (command[0] == "Substitute")
- {
- if (newRawPassword.ToString().Contains(command[1]))
- {
- newRawPassword = newRawPassword.Replace(command[1], command[2]);
- Console.WriteLine(newRawPassword);
- }
- else
- {
- Console.WriteLine("Nothing to replace!");
- }
- }
- }
- Console.WriteLine($"Your password is: {newRawPassword}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement