Advertisement
Prohause

Exam 14010.2018 Problem 01

Oct 14th, 2018
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. ?using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. namespace Problem_01
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. var lines = int.Parse(Console.ReadLine());
  11. var data = 0;
  12. for (int i = 0; i < lines; i++)
  13. {
  14. var regex = new Regex(@"^s:([^\;]+);r:([^\;]+);m--(""[a-zA-Z ]+"")");
  15. var matcher = regex.Match(Console.ReadLine());
  16. if (!matcher.Success) continue;
  17. var sender = matcher.Groups[1].Value;
  18. var receiver = matcher.Groups[2].Value;
  19. var message = matcher.Groups[3].Value;
  20.  
  21. foreach (var c in sender)
  22. {
  23. if (char.IsDigit(c))
  24. {
  25. data += int.Parse(c.ToString());
  26. }
  27.  
  28. if (char.IsLetter(c)||c.Equals(' '))
  29. {
  30. Console.Write(c);
  31. }
  32.  
  33. }
  34. Console.Write(" ");
  35. Console.Write($"says {message} to ");
  36.  
  37. foreach (var c in receiver)
  38. {
  39. if (char.IsDigit(c))
  40. {
  41. data += int.Parse(c.ToString());
  42. }
  43.  
  44. if (char.IsLetter(c) || c.Equals(' '))
  45. {
  46. Console.Write(c);
  47. }
  48.  
  49. }
  50.  
  51. Console.WriteLine();
  52. }
  53.  
  54. Console.WriteLine($"Total data transferred: {data}MB");
  55. }
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement