Advertisement
Guest User

Untitled

a guest
Apr 8th, 2020
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 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. Console.WriteLine(sb.ToString());
  27. }
  28. if (commands[0] == "Cut")
  29. {
  30. int index = int.Parse(commands[1]);
  31. int length = int.Parse(commands[2]);
  32. password = sb.ToString().Remove(index, length);
  33. Console.WriteLine(password);
  34.  
  35. }
  36. else if (commands[0] == "Substitute")
  37. {
  38. string substring = commands[1];
  39. string substitute = commands[2];
  40. if (password.Contains(substring))
  41. {
  42. password = password.Replace(substring, substitute);
  43. Console.WriteLine(password);
  44. }
  45. else
  46. {
  47. Console.WriteLine("Nothing to replace!");
  48. }
  49. }
  50. }
  51. Console.WriteLine($"Your password is: {password}");
  52. }
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement