Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- using System.Text.RegularExpressions;
- namespace Animal_Sanctuary
- {
- class Program
- {
- static void Main()
- {
- string pattern = @"n:(?<name>[\W\w]+);t:(?<kind>[\W\w]+);c--(?<country>[A-Za-z\s]+)";
- int numberInputs = int.Parse(Console.ReadLine());
- int totalKG = 0;
- for (int i = 0; i < numberInputs; i++)
- {
- string input = Console.ReadLine();
- Match validityCheck = Regex.Match(input, pattern);
- if (validityCheck.Success)
- {
- string name = validityCheck.Groups["name"].Value.ToString();
- string kind = validityCheck.Groups["kind"].Value.ToString();
- string country = validityCheck.Groups["country"].Value.ToString();
- totalKG += SumKilograms(name) + SumKilograms(kind);
- name = GetNameKind(name);
- kind = GetNameKind(kind);
- Console.WriteLine($"{name} is a {kind} from {country}");
- }
- }
- Console.WriteLine($"Total weight of animals: {totalKG}KG");
- }
- static string GetNameKind(string text)
- {
- string animalData = "";
- for (int i = 0; i < text.Length; i++)
- {
- if (char.IsLetter(text[i]) || text[i] == ' ')
- {
- animalData += text[i];
- }
- }
- return animalData;
- }
- static int SumKilograms(string text)
- {
- int sum = 0;
- for (int i = 0; i < text.Length; i++)
- {
- if (char.IsDigit(text[i]))
- {
- sum += text[i] - 48;
- }
- }
- return sum;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement