Advertisement
Guest User

Untitled

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