mattnguyen

My Retake Final Exam 11/04/2022 Problem 1 (solution 1)

Apr 11th, 2022
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6.  
  7. namespace PFFinalExamRetake13December2019
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. string skill = Console.ReadLine();
  14. string input = string.Empty;
  15. bool exist = false;
  16. while ((input = Console.ReadLine()) != "For Azeroth")
  17. {
  18. exist = false;
  19. string[] splittedInput = input.Split();
  20.  
  21. if (splittedInput.Contains("GladiatorStance"))
  22. {
  23. skill = skill.ToUpper();
  24. Console.WriteLine(skill);
  25. exist = true;
  26.  
  27. }
  28. else if (splittedInput.Contains("DefensiveStance"))
  29. {
  30. skill = skill.ToLower();
  31. Console.WriteLine(skill);
  32. exist = true;
  33.  
  34. }
  35. else if (splittedInput.Contains("Dispel"))
  36. {
  37. exist = true;
  38. int index = int.Parse(splittedInput[1]);
  39. char letter = char.Parse(splittedInput[2]);
  40. if (index > skill.Length - 1 || index < 0)
  41. {
  42. Console.WriteLine("Dispel too weak.");
  43.  
  44. }
  45. else
  46. {
  47. skill = skill.Remove(index, 1);
  48. skill = skill.Insert(index, letter.ToString());
  49. Console.WriteLine("Success!");
  50.  
  51. }
  52. }
  53. else if (splittedInput.Contains("Target"))
  54. {
  55. if (splittedInput[1] == "Change")
  56. {
  57. exist = true;
  58. string stringToBeChanged = splittedInput[2];
  59. string newString = splittedInput[3];
  60. if (skill.Contains(stringToBeChanged))
  61. {
  62. skill = skill.Replace(stringToBeChanged, newString);
  63. Console.WriteLine(skill);
  64. }
  65.  
  66. }
  67. else if (splittedInput[1] == "Remove")
  68. {
  69. exist = true;
  70. string stringToBeChanged = splittedInput[2];
  71. int indexOf = skill.IndexOf(stringToBeChanged);
  72. int lenght = stringToBeChanged.Length;
  73. if (indexOf != -1)
  74. {
  75. skill = skill.Remove(indexOf, lenght);
  76. Console.WriteLine(skill);
  77. }
  78.  
  79. }
  80. }
  81. if (exist == false)
  82. {
  83. Console.WriteLine("Command doesn't exist!");
  84. }
  85.  
  86.  
  87. }
  88. }
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment