Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text.RegularExpressions;
- namespace _01._Animal_Sanctuary
- {
- class Program
- {
- static void Main(string[] args)
- {
- string pattern = @"n:(?<name>.+?);t:(?<kind>.+?);c--(?<country>[A-Za-z\s]+)";
- int totalWeight = 0;
- int numberOflines = int.Parse(Console.ReadLine());
- for (int i = 0; i < numberOflines; i++)
- {
- string input = Console.ReadLine();
- Match match = Regex.Match(input, pattern);
- if (match.Success)
- {
- string encryptedName = match.Groups["name"].Value;
- string name = DecryptString(encryptedName);
- string encryptedKind = match.Groups["kind"].Value;
- string kind = DecryptString(encryptedKind);
- string country = match.Groups["country"].Value;
- totalWeight += SumInputDigits($"{encryptedName}{encryptedKind}");
- Console.WriteLine($"{name} is a {kind} from {country}");
- }
- }
- Console.WriteLine($"Total weight of animals: {totalWeight}KG");
- }
- private static int SumInputDigits(string match)
- {
- int sum = 0;
- for (int i = 0; i < match.Length; i++)
- {
- if (char.IsDigit(match[i]))
- {
- sum += match[i] - 48;
- }
- }
- return sum;
- }
- private static string DecryptString(string encryptedName)
- {
- string name = string.Empty;
- for (int i = 0; i < encryptedName.Length; i++)
- {
- if (char.IsLetter(encryptedName[i]))
- {
- name += encryptedName[i];
- }
- }
- return name;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement