Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text.RegularExpressions;
- using System.Linq;
- namespace _01._Animal_Sanctuary
- {
- class Program
- {
- static void Main()
- {
- var countLines = int.Parse(Console.ReadLine());
- var weightOfAnimals = 0;
- for (int i = 0; i < countLines; i++)
- {
- var input = Console.ReadLine();
- var splittedInput = input
- .Split(";", StringSplitOptions.RemoveEmptyEntries);
- var checkIsValid = true;
- if (splittedInput.Length == 3)
- {
- var name = splittedInput[0];
- var kind = splittedInput[1];
- var country = splittedInput[2];
- if (name[0] != 'n' || name[1] != ':')
- {
- checkIsValid = false;
- }
- if (kind[0] != 't' || kind[1] != ':')
- {
- checkIsValid = false;
- }
- if (country[0] != 'c' ||
- country[1] != '-' ||
- country[2] != '-')
- {
- checkIsValid = false;
- }
- if (checkIsValid)
- {
- name = name.Substring(2);
- kind = kind.Substring(2);
- country = country.Substring(3);
- var pattern = @"[A-Za-z]+";
- var nameAfterRegex = Regex.Matches(name, pattern);
- var kindAfterRegex = Regex.Matches(kind, pattern);
- var countryAfterRegex = Regex.Matches(country, pattern);
- foreach (var item in nameAfterRegex)
- {
- Console.Write(item);
- }
- Console.Write(" is a ");
- foreach (var item in kindAfterRegex)
- {
- Console.Write(item);
- }
- Console.Write(" from ");
- foreach (var item in countryAfterRegex)
- {
- Console.Write(item);
- }
- Console.WriteLine();
- for (int j = 0; j < input.Length; j++)
- {
- var symbol = input[j];
- if (char.IsDigit(symbol))
- {
- weightOfAnimals += (symbol - 48);
- }
- }
- }
- }
- }
- Console.WriteLine($"Total weight of animals: {weightOfAnimals}KG");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement