Advertisement
North_Point

Fish Statistics

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