Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Numerics;
- using System.Text;
- using System.Text.RegularExpressions;
- namespace Final_Exam
- {
- class Animal
- {
- static void Main(string[] args)
- {
- int count = int.Parse(Console.ReadLine());
- double sumKg = 0;
- for (int i = 0; i < count; i++)
- {
- string inputText = Console.ReadLine();
- if (inputText.Contains("n:") && inputText.Contains(";t:") && inputText.Contains(";c--"))
- {
- string[] input = inputText.Split(";");
- string name = input[0];
- string correctName = string.Empty;
- if (name.IndexOf("n:")==0)
- {
- correctName = new string(name.Where(x => char.IsLetter(x) || x == ' ').ToArray());
- correctName = correctName.Substring(1);
- string digitsInName = new string(name.Where(x => char.IsDigit(x)).ToArray());
- sumKg += digitsInName.Select(x => double.Parse(x.ToString())).Sum();
- }
- string kind = input[1];
- string correctKind = string.Empty;
- if (kind.IndexOf("t:") == 0)
- {
- correctKind = new string(kind.Where(x => char.IsLetter(x) || x == ' ').ToArray());
- correctKind = correctKind.Substring(1);
- string digitsInKind = new string(kind.Where(x => char.IsDigit(x)).ToArray());
- sumKg += digitsInKind.Select(x => double.Parse(x.ToString())).Sum();
- }
- string country = input[2];
- string correctCountry = string.Empty;
- if (country.IndexOf("c--") == 0)
- {
- correctCountry = new string(country.Where(x => char.IsLetter(x) || x == ' ').ToArray());
- correctCountry = correctCountry.Substring(1);
- }
- Console.WriteLine($"{correctName} is a {correctKind} from {correctCountry}");
- }
- }
- Console.WriteLine("Total weight of animals: {0}KG", sumKg);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement