Advertisement
Guest User

Untitled

a guest
Dec 10th, 2020
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3. using System.Linq;
  4.  
  5. namespace FinalExamPasswordReset
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. string password = Console.ReadLine();
  12.  
  13. string input;
  14. StringBuilder sb = new StringBuilder();
  15. while ((input = Console.ReadLine()) != "Done")
  16. {
  17. string[] commands = input.Split(' ', StringSplitOptions.RemoveEmptyEntries);
  18. if (commands[0] == "TakeOdd")
  19. {
  20. for (int i = 1; i < password.Length; i+=2)
  21. {
  22. char currentChar = password[i];
  23. sb.Append(currentChar);
  24.  
  25. }
  26.  
  27. password = sb.ToString(); // => добавено
  28. Console.WriteLine(sb.ToString());
  29. }
  30. if (commands[0] == "Cut")
  31. {
  32. int index = int.Parse(commands[1]);
  33. int length = int.Parse(commands[2]);
  34. password = password.Remove(index, length); //password = sb.ToString().Remove(index, length) променено
  35. Console.WriteLine(password);
  36.  
  37. }
  38. else if (commands[0] == "Substitute")
  39. {
  40. string substring = commands[1];
  41. string substitute = commands[2];
  42. if (password.Contains(substring))
  43. {
  44. password = password.Replace(substring, substitute);
  45. Console.WriteLine(password);
  46. }
  47. else
  48. {
  49. Console.WriteLine("Nothing to replace!");
  50. }
  51. }
  52. }
  53. Console.WriteLine($"Your password is: {password}");
  54. }
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement