Advertisement
Guest User

FishStatistics

a guest
Aug 11th, 2017
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.83 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 _06_fishStatistics
  9. {
  10.     class fishStatistics
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             string input = Console.ReadLine();
  15.  
  16.             string pattern = @"(?<tail>>*)<(?<body>\(*)(?<status>['\-x])>";
  17.  
  18.             MatchCollection matchedfishes = Regex.Matches(input, pattern);
  19.             if (matchedfishes.Count > 0)
  20.             {
  21.                 int count = 0;
  22.                 foreach (Match fish in matchedfishes)
  23.                 {
  24.                     count++;
  25.                     string tail = fish.Groups["tail"].Value;
  26.                     string body = fish.Groups["body"].Value;
  27.                     string status = fish.Groups["status"].Value;
  28.  
  29.                     Console.WriteLine($"Fish {count}: {fish.Value}");
  30.                     Console.WriteLine($"  Tail type: {TailLength(tail)}");
  31.                     Console.WriteLine($"  Body type: {BodyLength(body)}");
  32.                     Console.WriteLine($"  Status: {FishStatus(status)}");
  33.                 }
  34.             }
  35.             else
  36.             {
  37.                 Console.WriteLine("No fish found.");
  38.             }      
  39.    
  40.         }
  41.  
  42.         public static string TailLength(string tail)
  43.         {
  44.             if (tail.Length > 0)
  45.             {
  46.                 int tailLength = tail.Length * 2;
  47.  
  48.                 if (tail.Length > 5)
  49.                 {
  50.                     return $"Long ({tailLength} cm)";
  51.                 }
  52.                 else if (tail.Length == 1)
  53.                 {
  54.                     return $"Short ({tailLength} cm)";
  55.                 }
  56.                 else
  57.                 {
  58.                     return $"Medium ({tailLength} cm)";
  59.                 }                
  60.             }            
  61.             else
  62.             {
  63.                 return "None";
  64.             }
  65.         }
  66.  
  67.         public static string BodyLength(string body)
  68.         {
  69.             int bodyLength = body.Length * 2;
  70.  
  71.             if(body.Length > 10)
  72.             {
  73.                 return $"Long ({bodyLength} cm)";
  74.             }
  75.             else if(body.Length > 5)
  76.             {
  77.                 return $"Medium ({bodyLength} cm)";
  78.             }
  79.             else
  80.             {
  81.                 return $"Short ({bodyLength} cm)";
  82.             }
  83.         }
  84.  
  85.         public static string FishStatus(string status)
  86.         {
  87.             switch (status)
  88.             {
  89.                 case "'":
  90.                     return "Awake";
  91.                 case "-":
  92.                     return "Asleep";
  93.                 case "x":
  94.                     return "Dead";
  95.                 default:
  96.                      return "";                  
  97.             }
  98.         }
  99.     }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement