Advertisement
Aborigenius

6.Fish Statistics

Aug 27th, 2017
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.71 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7.  
  8. namespace FishStatistics
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             Regex pattern = new Regex(@"(?<fish>(?<tail>[>]*)[<](?<body>\(+)(?<status>'|-|x)>)");
  15.  
  16.             string input = Console.ReadLine();
  17.             string TailType = string.Empty;
  18.             string BodyType = string.Empty;
  19.             string status = string.Empty;
  20.             int bodyLenght = 0;
  21.             int tailLenght = 0;
  22.             if (pattern.IsMatch(input))
  23.             {
  24.                 MatchCollection test = pattern.Matches(input);
  25.                 int fishIndex = 1;
  26.                 foreach (Match fish in test)
  27.                 {
  28.                  
  29.                     foreach (Capture capture in fish.Captures)
  30.                     {
  31.                         string tail = fish.Groups["tail"].Value;
  32.                         string body = fish.Groups["body"].Value;
  33.                          status = fish.Groups["status"].Value;
  34.                          tailLenght = tail.Length;
  35.                          bodyLenght = body.Length;
  36.                          TailType = string.Empty;
  37.                          BodyType = string.Empty;
  38.                         if (status == "'")
  39.                         {
  40.                             status = "Awake";
  41.                         }
  42.                         if (status == "-")
  43.                         {
  44.                             status = "Asleep";
  45.                         }
  46.                         if (status == "x")
  47.                         {
  48.                             status = "Dead";
  49.                         }
  50.                         if (tailLenght == 0)
  51.                         {
  52.                             TailType = "None";
  53.                         }
  54.                         if (tailLenght == 1)
  55.                         {
  56.                             TailType = "Short";
  57.                         }
  58.                         if (tailLenght > 1 && tailLenght <= 5)
  59.                         {
  60.                             TailType = "Medium";
  61.                         }
  62.                         if (tailLenght >  5)
  63.                         {
  64.                             TailType = "Long";
  65.                         }
  66.                         if (bodyLenght < 5)
  67.                         {
  68.                             BodyType = "Short";
  69.                         }
  70.                         if (bodyLenght >=5 && bodyLenght < 10)
  71.                         {
  72.                             BodyType = "Medium";
  73.                         }
  74.                         if (bodyLenght >= 10)
  75.                         {
  76.                             BodyType = "Long";
  77.                         }
  78.  
  79.  
  80.                     }
  81.                     Console.WriteLine($"Fish {fishIndex}: {fish}");
  82.                     if (TailType == "None")
  83.                     {
  84.                         Console.WriteLine($" Tail type: {TailType}");
  85.                         Console.WriteLine($"  Body type: {BodyType} ({bodyLenght * 2} cm)");
  86.                         Console.WriteLine($"  Status: {status}");
  87.                     }
  88.                     else
  89.                     {
  90.                         Console.WriteLine($"  Tail type: {TailType} ({tailLenght * 2} cm)");
  91.                         Console.WriteLine($"  Body type: {BodyType} ({bodyLenght * 2} cm)");
  92.                         Console.WriteLine($"  Status: {status}");
  93.                     }
  94.                     fishIndex++;
  95.                 }
  96.             }
  97.             else
  98.             {
  99.                 Console.WriteLine("No fish found.");
  100.             }
  101.  
  102.         }
  103.     }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement