Advertisement
Guest User

problem3

a guest
Jun 1st, 2015
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Collections.Generic;
  7. using System.Text.RegularExpressions;
  8.  
  9. namespace Problem3
  10. {
  11. class Problem3
  12. {
  13. static void Main(string[] args)
  14. {
  15. StringBuilder bld = new StringBuilder();
  16. StringBuilder result = new StringBuilder();
  17.  
  18. String str;
  19. while (true)
  20. {
  21. str = Console.ReadLine();
  22. if (str == "burp")
  23. {
  24. break;
  25. }
  26.  
  27. str = Regex.Replace(str, @"([ ]{2,})", " ");
  28.  
  29. bld.Append(str);
  30. }
  31.  
  32. str = bld.ToString();
  33. //Console.WriteLine(str);
  34. String pattern = @"(?<symbol>[$%&']{1})(?<text>[^$%&']+)(\k<symbol>)";
  35.  
  36. Regex rex = new Regex(pattern);
  37. Match match = rex.Match(str);
  38.  
  39. //Console.WriteLine(match.Success);
  40. while (match.Success)
  41. {
  42. String special = match.Groups["symbol"].Value;
  43. String text = match.Groups["text"].Value;
  44. // Console.WriteLine(special + " " + text);
  45.  
  46. result.Append(GetResult(special, text) + " ");
  47.  
  48. match = match.NextMatch();
  49. }
  50.  
  51. Console.WriteLine(result.ToString());
  52. }
  53.  
  54. private static String GetResult(String special, String text)
  55. {
  56. StringBuilder bld = new StringBuilder();
  57. int weight = GetWeight(special);
  58. int flag = 0;
  59. for (int i = 0; i < text.Length; i++)
  60. {
  61. if (flag == 0)
  62. {
  63. bld.Append(char.ToString((char)(text[i] + weight)));
  64. flag = 1;
  65. }
  66. else
  67. {
  68. bld.Append(char.ToString((char)(text[i] - weight)));
  69. flag = 0;
  70. }
  71. }
  72.  
  73. return bld.ToString();
  74. }
  75.  
  76. private static int GetWeight(String special)
  77. {
  78. switch (special)
  79. {
  80. case "$":
  81. return 1;
  82. case "%":
  83. return 2;
  84. case "&":
  85. return 3;
  86. case "'":
  87. return 4;
  88. default:
  89. return 0;
  90. }
  91. }
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement