Advertisement
fr3s7ed

Untitled

Oct 14th, 2018
109
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.RegularExpressions;
  5.  
  6. namespace Data_Transfer
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. int count = int.Parse(Console.ReadLine());
  13.  
  14. string asd = @"([A-Za-z ]+)";
  15. string pattern = $@"s:([^;]*);r:([^\;]*);m--""{asd}""";
  16.  
  17. Regex regex = new Regex(pattern);
  18.  
  19. List<long> allDigits = new List<long>();
  20. for (int i = 0; i < count; i++)
  21. {
  22. string input = Console.ReadLine();
  23.  
  24. string sender = string.Empty;
  25. string reciver = string.Empty;
  26. string message = string.Empty;
  27.  
  28. if (regex.IsMatch(input))
  29. {
  30. MatchCollection match = regex.Matches(input);
  31.  
  32. string rough = match[0].Groups[1].Value;
  33.  
  34. message = match[0].Groups[3].Value;
  35. for (int j = 0; j < rough.Length; j++)
  36. {
  37. if (Char.IsNumber(rough[j]))
  38. {
  39. allDigits.Add((int)char.GetNumericValue(rough[j]));
  40. }
  41.  
  42. if(Char.IsLetter(rough[j]) || rough[j] == ' ')
  43. {
  44. sender += rough[j];
  45. }
  46. }
  47.  
  48. string roughReciver = match[0].Groups[2].Value;
  49.  
  50. for (int j = 0; j < roughReciver.Length; j++)
  51. {
  52. if (Char.IsDigit(roughReciver[j]))
  53. {
  54. allDigits.Add((int)char.GetNumericValue(roughReciver[j]));
  55. }
  56.  
  57. if (Char.IsLetter(roughReciver[j]) || roughReciver[j] == ' ')
  58. {
  59. reciver += roughReciver[j];
  60. }
  61. }
  62. Console.WriteLine($"{sender} says \"" + $"{message}" + "\"" + $" to {reciver}");
  63. }
  64. }
  65. Console.WriteLine($"Total data transferred: {allDigits.Sum()}MB");
  66. }
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement