Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Text;
- namespace Problem_1._Password_Reset
- {
- class Program
- {
- static void Main(string[] args)
- {
- string password = Console.ReadLine();
- string input;
- string oddText = string.Empty;
- while ((input = Console.ReadLine()) != "Done")
- {
- string[] split = input.Split();
- string command = split[0];
- if (command == "TakeOdd")
- {
- for (int i = 1; i < password.Length; i += 2)
- {
- oddText += password[i];
- }
- password = oddText;
- Console.WriteLine(password);
- //result = string.Concat(password.Where((c, i) => i % 2 != 0));
- //Console.WriteLine(result);
- }
- //Cut 15 3
- if (command == "Cut")
- {
- int index = int.Parse(split[1]);
- int lenght = int.Parse(split[2]);
- if (!(index >= password.Length || lenght > password.Length))
- {
- password = password.Remove(index, lenght);
- //result = result.Substring(0, index) + result.Substring(lenght + 1);
- Console.WriteLine(password);
- }
- else
- {
- break;
- }
- }
- //Substitute :: -
- if (command == "Substitute")
- {
- string substring = split[1];
- string substitute = split[2];
- if (password.Contains(substring))
- {
- password = password.Replace(substring, substitute);
- Console.WriteLine(password);
- }
- else
- {
- Console.WriteLine("Nothing to replace!");
- }
- }
- }
- Console.WriteLine($"Your password is: {password}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement