Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- namespace FishStatistics
- {
- class Program
- {
- static void Main(string[] args)
- {
- Regex pattern = new Regex(@"(?<fish>(?<tail>[>]*)[<](?<body>\(+)(?<status>'|-|x)>)");
- string input = Console.ReadLine();
- string TailType = string.Empty;
- string BodyType = string.Empty;
- string status = string.Empty;
- int bodyLenght = 0;
- int tailLenght = 0;
- if (pattern.IsMatch(input))
- {
- MatchCollection test = pattern.Matches(input);
- int fishIndex = 1;
- foreach (Match fish in test)
- {
- foreach (Capture capture in fish.Captures)
- {
- string tail = fish.Groups["tail"].Value;
- string body = fish.Groups["body"].Value;
- status = fish.Groups["status"].Value;
- tailLenght = tail.Length;
- bodyLenght = body.Length;
- TailType = string.Empty;
- BodyType = string.Empty;
- if (status == "'")
- {
- status = "Awake";
- }
- if (status == "-")
- {
- status = "Asleep";
- }
- if (status == "x")
- {
- status = "Dead";
- }
- if (tailLenght == 0)
- {
- TailType = "None";
- }
- if (tailLenght == 1)
- {
- TailType = "Short";
- }
- if (tailLenght > 1 && tailLenght <= 5)
- {
- TailType = "Medium";
- }
- if (tailLenght > 5)
- {
- TailType = "Long";
- }
- if (bodyLenght < 5)
- {
- BodyType = "Short";
- }
- if (bodyLenght >=5 && bodyLenght < 10)
- {
- BodyType = "Medium";
- }
- if (bodyLenght >= 10)
- {
- BodyType = "Long";
- }
- }
- Console.WriteLine($"Fish {fishIndex}: {fish}");
- if (TailType == "None")
- {
- Console.WriteLine($" Tail type: {TailType}");
- Console.WriteLine($" Body type: {BodyType} ({bodyLenght * 2} cm)");
- Console.WriteLine($" Status: {status}");
- }
- else
- {
- Console.WriteLine($" Tail type: {TailType} ({tailLenght * 2} cm)");
- Console.WriteLine($" Body type: {BodyType} ({bodyLenght * 2} cm)");
- Console.WriteLine($" Status: {status}");
- }
- fishIndex++;
- }
- }
- else
- {
- Console.WriteLine("No fish found.");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement