Advertisement
EmoRz

01. Data Transfer

Oct 15th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.44 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace DataTransfer
  7. {
  8.     class Start
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             string patttern = @"s\:([^\;]+)\;r\:([^\;]+)\;";
  13.             string newPattern = @"s\:([^\;]+)\;r\:([^\;]+)\;m--""([A-Za-z ]+)""";
  14.            
  15.             int num = int.Parse(Console.ReadLine());
  16.             int sum = 0;
  17.  
  18.             for (int i = 0; i < num; i++)
  19.             {
  20.                 string inputStr = Console.ReadLine();
  21.                 MatchCollection match = Regex.Matches(inputStr, newPattern);  
  22.  
  23.                 foreach (Match item in match)
  24.                 {
  25.                     var senderP = "";
  26.                     var recieverP = "";
  27.                     var message = "";
  28.                     senderP = GetData(item.Groups[1].Value);
  29.                     recieverP = GetData(item.Groups[2].Value);
  30.                     message = GetData(item.Groups[3].Value);
  31.                     string allDigitsFrom = item.Groups[1].Value.ToString()+item.Groups[2].Value.ToString();
  32.                     sum += IsDigit(allDigitsFrom);
  33.                     Console.WriteLine($"{senderP} says \"{message}\" to {recieverP}");
  34.                 }
  35.             }
  36.             int total = sum;
  37.             Console.WriteLine($"Total data transferred: {total}MB");  
  38.         }
  39.  
  40.         private static int IsDigit(string value1)
  41.         {
  42.             int sum = 0;
  43.             string word = value1;
  44.             foreach (var it in word)
  45.             {
  46.                 if (Char.IsDigit(it))
  47.                 {
  48.                     sum += Convert.ToInt32(it.ToString());
  49.                 }
  50.             }
  51.             return sum;
  52.         }
  53.  
  54.         private static string GetData(string word)
  55.         {
  56.             string info = "";
  57.             foreach (var it in word)
  58.             {                
  59.                 if (Char.IsLetter(it) || it == ' ')
  60.                 {
  61.                     info += it;
  62.                 }                
  63.             }
  64.    
  65.             return info;
  66.         }
  67.  
  68.         private static int Calculate(string senderP, string senderP1, string message)
  69.         {
  70.             int sum = 0;
  71.             var all = (senderP + senderP1);
  72.             for (int i = 0; i < all.Length; i++)
  73.             {
  74.                 sum += Convert.ToInt32(all[i]);
  75.             }
  76.             return sum;
  77.         }
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement