Advertisement
cap7ainjack

Text_transformer

Oct 10th, 2015
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7.  
  8. namespace _3_Text_Transformer_May_2015
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14. string input = Console.ReadLine();
  15. StringBuilder builder = new StringBuilder();
  16. while (input != "burp")
  17. {
  18. builder.Append(input);
  19.  
  20. input = Console.ReadLine();
  21. }
  22.  
  23. //remove whitespaces
  24. string text = Regex.Replace(builder.ToString(), @"\s+", " ");
  25.  
  26. FindWords(text);
  27.  
  28. }
  29.  
  30. private static void FindWords(string text)
  31. {
  32. string pattern = @"([\$\'\%\&])(\w+)(\1)";
  33. Regex wordFinder = new Regex(pattern);
  34.  
  35. MatchCollection matches = wordFinder.Matches(text);
  36. StringBuilder results = new StringBuilder();
  37. int weight=0;
  38. foreach (Match word in matches)
  39. {
  40.  
  41. switch (word.Groups[1].Value)
  42. {
  43. case "$":
  44. weight = 1;
  45. break;
  46. case "%":
  47. weight = 2;
  48. break;
  49. case "&":
  50. weight = 3;
  51. break;
  52. case "'":
  53. weight = 4;
  54. break;
  55. }
  56.  
  57. char[] letter = word.Groups[2].Value.ToCharArray();
  58. char currentLetter;
  59. for (int i = 0; i < letter.Length; i++)
  60. {
  61. if (i % 2 ==0)
  62. {
  63. currentLetter =(char)(letter[i] + weight);
  64. results.Append(currentLetter);
  65. }
  66.  
  67. else
  68. {
  69. currentLetter = (char)(letter[i] - weight);
  70. results.Append(currentLetter);
  71. }
  72.  
  73. }
  74.  
  75. Console.Write(results + " ");
  76. results.Clear();
  77. }
  78.  
  79. // Console.WriteLine();
  80. }
  81. }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement