Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text;
- class Program
- {
- static void Main()
- {
- string pass = Console.ReadLine();
- string input;
- while ((input = Console.ReadLine()) != "Done")
- {
- string[] cmd = input.Split();
- switch (cmd[0])
- {
- case "TakeOdd":
- pass = TakeOdd(pass);
- Console.WriteLine(pass);
- break;
- case "Cut":
- pass = Cut(pass, int.Parse(cmd[1]), int.Parse(cmd[2]));
- Console.WriteLine(pass);
- break;
- case "Substitute":
- pass = Substitute(pass, cmd[1], cmd[2]); break;
- }
- }
- Console.WriteLine($"Your password is: {pass}");
- }
- private static string Substitute(string pass, string subString, string replacement)
- {
- if (!pass.Contains(subString))
- {
- Console.WriteLine($"Nothing to replace!");
- return pass;
- }
- string newPass = pass.Replace(subString, replacement);
- Console.WriteLine(newPass);
- return newPass;
- }
- private static string Cut(string pass, int index, int length)
- {
- string subString = pass.Substring(index, length);
- int position = pass.IndexOf(subString);
- return pass.Remove(position, length);
- }
- private static string TakeOdd(string pass)
- {
- StringBuilder newPass = new StringBuilder();
- for (int i = 1; i < pass.Length; i += 2)
- newPass.Append(pass[i]);
- return newPass.ToString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement