Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
737
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Text;
  4.  
  5. namespace Password_Reset
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. string text = Console.ReadLine();
  12.  
  13. StringBuilder sb = new StringBuilder();
  14. string password = "";
  15. string command = Console.ReadLine();
  16.  
  17. while (command != "Done")
  18. {
  19. string[] splitted = command.Split(' ');
  20.  
  21. string action = splitted[0];
  22.  
  23. if (action == "TakeOdd")
  24. {
  25. for (int i = 1; i < text.Length; i += 2)
  26. {
  27. sb.Append(text[i]);
  28.  
  29. }
  30.  
  31. Console.WriteLine(sb.ToString());
  32.  
  33. }
  34. else if (action == "Cut")
  35. {
  36. int startIndex = int.Parse(splitted[1]);
  37. int lenght = int.Parse(splitted[2]);
  38. int test = startIndex + lenght;
  39.  
  40. if (test > password.Length)
  41. {
  42. continue;
  43. }
  44. sb.Remove(startIndex, lenght);
  45.  
  46.  
  47. Console.WriteLine(password);
  48. }
  49. else if (action == "Substitute")
  50. {
  51. string chReplace = splitted[1];
  52. string newChar = splitted[2];
  53.  
  54. if (password.Contains(chReplace))
  55. {
  56. sb.Replace(chReplace, newChar);
  57. Console.WriteLine(password);
  58. }
  59. else
  60. {
  61. Console.WriteLine("Nothing to replace!");
  62. }
  63. }
  64. password = sb.ToString();
  65. command = Console.ReadLine();
  66. }
  67.  
  68. Console.WriteLine($"Your password is: {password}");
  69. }
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement