Advertisement
Guest User

Untitled

a guest
Jul 14th, 2019
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.42 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Numerics;
  5. using System.Text;
  6. using System.Text.RegularExpressions;
  7.  
  8. namespace Final_Exam
  9. {
  10.     class Animal
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             int count = int.Parse(Console.ReadLine());
  15.             double sumKg = 0;
  16.  
  17.             for (int i = 0; i < count; i++)
  18.             {
  19.                 string inputText = Console.ReadLine();
  20.                
  21.                 if (inputText.Contains("n:") && inputText.Contains(";t:") && inputText.Contains(";c--"))
  22.                 {
  23.                     string[] input = inputText.Split(";");
  24.  
  25.                     string name = input[0];
  26.                     string correctName = string.Empty;                  
  27.                     if (name.IndexOf("n:")==0)
  28.                     {
  29.                         correctName = new string(name.Where(x => char.IsLetter(x) || x == ' ').ToArray());
  30.                         correctName = correctName.Substring(1);
  31.                         string digitsInName = new string(name.Where(x => char.IsDigit(x)).ToArray());
  32.                         sumKg += digitsInName.Select(x => double.Parse(x.ToString())).Sum();                  
  33.                     }
  34.  
  35.                     string kind = input[1];
  36.                     string correctKind = string.Empty;
  37.                     if (kind.IndexOf("t:") == 0)
  38.                     {
  39.                         correctKind = new string(kind.Where(x => char.IsLetter(x) || x == ' ').ToArray());
  40.                         correctKind = correctKind.Substring(1);
  41.                         string digitsInKind = new string(kind.Where(x => char.IsDigit(x)).ToArray());
  42.                         sumKg += digitsInKind.Select(x => double.Parse(x.ToString())).Sum();
  43.                     }
  44.  
  45.                     string country = input[2];
  46.                     string correctCountry = string.Empty;
  47.                     if (country.IndexOf("c--") == 0)
  48.                     {
  49.                         correctCountry = new string(country.Where(x => char.IsLetter(x) || x == ' ').ToArray());
  50.                         correctCountry = correctCountry.Substring(1);
  51.                     }
  52.  
  53.                     Console.WriteLine($"{correctName} is a {correctKind} from {correctCountry}");
  54.                    
  55.                 }
  56.             }
  57.             Console.WriteLine("Total weight of animals: {0}KG", sumKg);
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement