Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.59 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Text.RegularExpressions;
  4.  
  5. namespace _01._Animal_Sanctuary
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             int lines = int.Parse(Console.ReadLine());
  12.             int kilo = 0;
  13.  
  14.             for (int i = 0; i < lines; i++)
  15.             {
  16.                 string regex = @"n:(?<name>[^;]+);t:(?<kind>[^;]+);c--(?<country>[A-z ]+)";
  17.  
  18.                 string input = Console.ReadLine();
  19.                 MatchCollection matched = Regex.Matches(input, regex);
  20.  
  21.                 foreach (Match m in matched)
  22.                 {
  23.                     var name = m.Groups["name"].Value;
  24.                     var kind = m.Groups["kind"].Value;
  25.                     var country = m.Groups["country"].Value;
  26.                     var kName = Regex.Replace(name, "[^0-9]", "");
  27.                     var kKind = Regex.Replace(kind, "[^0-9]", "");
  28.                     kilo += kName.ToString().Sum(c => c - '0');
  29.                     kilo += kKind.ToString().Sum(c => c - '0');
  30.                     var rName = new string(name.Where(c => char.IsLetter(c) || char.IsWhiteSpace(c)).ToArray());
  31.                     var rKind = new string(kind.Where(c => char.IsLetter(c) || char.IsWhiteSpace(c)).ToArray());
  32.                     //rName = Regex.Replace(name, "^", "");
  33.                     //rKind = Regex.Replace(kind, "^", "");
  34.  
  35.                     Console.WriteLine($"{rName} is a {rKind} from {country}");
  36.                 }              
  37.             }
  38.             Console.WriteLine($"Total weight of animals: {kilo}KG");
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement