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 _06_fishStatistics
- {
- class fishStatistics
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- string pattern = @"(?<tail>>*)<(?<body>\(*)(?<status>['\-x])>";
- MatchCollection matchedfishes = Regex.Matches(input, pattern);
- if (matchedfishes.Count > 0)
- {
- int count = 0;
- foreach (Match fish in matchedfishes)
- {
- count++;
- string tail = fish.Groups["tail"].Value;
- string body = fish.Groups["body"].Value;
- string status = fish.Groups["status"].Value;
- Console.WriteLine($"Fish {count}: {fish.Value}");
- Console.WriteLine($" Tail type: {TailLength(tail)}");
- Console.WriteLine($" Body type: {BodyLength(body)}");
- Console.WriteLine($" Status: {FishStatus(status)}");
- }
- }
- else
- {
- Console.WriteLine("No fish found.");
- }
- }
- public static string TailLength(string tail)
- {
- if (tail.Length > 0)
- {
- int tailLength = tail.Length * 2;
- if (tail.Length > 5)
- {
- return $"Long ({tailLength} cm)";
- }
- else if (tail.Length == 1)
- {
- return $"Short ({tailLength} cm)";
- }
- else
- {
- return $"Medium ({tailLength} cm)";
- }
- }
- else
- {
- return "None";
- }
- }
- public static string BodyLength(string body)
- {
- int bodyLength = body.Length * 2;
- if(body.Length > 10)
- {
- return $"Long ({bodyLength} cm)";
- }
- else if(body.Length > 5)
- {
- return $"Medium ({bodyLength} cm)";
- }
- else
- {
- return $"Short ({bodyLength} cm)";
- }
- }
- public static string FishStatus(string status)
- {
- switch (status)
- {
- case "'":
- return "Awake";
- case "-":
- return "Asleep";
- case "x":
- return "Dead";
- default:
- return "";
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement