Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text;
- using System.Linq;
- namespace FinalExamPasswordReset
- {
- class Program
- {
- static void Main(string[] args)
- {
- string password = Console.ReadLine();
- string input;
- StringBuilder sb = new StringBuilder();
- while ((input = Console.ReadLine()) != "Done")
- {
- string[] commands = input.Split(' ', StringSplitOptions.RemoveEmptyEntries);
- if (commands[0] == "TakeOdd")
- {
- for (int i = 1; i < password.Length; i+=2)
- {
- char currentChar = password[i];
- sb.Append(currentChar);
- }
- password = sb.ToString(); // => добавено
- Console.WriteLine(sb.ToString());
- }
- if (commands[0] == "Cut")
- {
- int index = int.Parse(commands[1]);
- int length = int.Parse(commands[2]);
- password = password.Remove(index, length); //password = sb.ToString().Remove(index, length) променено
- Console.WriteLine(password);
- }
- else if (commands[0] == "Substitute")
- {
- string substring = commands[1];
- string substitute = commands[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