Advertisement
valkata

RegEx Faces

Aug 12th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.89 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 _07_happinessIndex
  9. {
  10.     class happinessIndex
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             string input = Console.ReadLine();
  15.             Regex happyPattern = new Regex(@"(:\)|:D|;\)|:\*|:]|;]|:}|;}|\(:|\*:|c:|\[:|\[;)");
  16.             Regex sadPattern = new Regex(@"(:\(|D:|;\(|:\[|;\[|:\{|;\{|\):|:c|\]:|\];)");
  17.  
  18.             string[] happy = happyPattern.Matches(input)
  19.                 .Cast<Match>()
  20.                 .Select(h => h.Value)
  21.                 .ToArray();
  22.  
  23.             string[] sad = sadPattern.Matches(input)
  24.                 .Cast<Match>()
  25.                 .Select(s => s.Value)
  26.                 .ToArray();
  27.  
  28.             double happyCount = happy.Count();
  29.             double sadCount = sad.Count();
  30.  
  31.             double happyIndex = happyCount / sadCount;
  32.  
  33.             if (happyIndex >= 2.00)
  34.             {
  35.                 Console.WriteLine($"Happiness index: {happyIndex:F2} :D");
  36.                 Console.WriteLine($"[Happy count: {happyCount}, Sad count: {sadCount}]");
  37.             }
  38.             else if(happyIndex > 1.00)
  39.             {
  40.                 Console.WriteLine($"Happiness index: {happyIndex:F2} :)");
  41.                 Console.WriteLine($"[Happy count: {happyCount}, Sad count: {sadCount}]");
  42.             }
  43.             else if(happyIndex == 1.00)
  44.             {
  45.                 Console.WriteLine($"Happiness index: {happyIndex:F2} :|");
  46.                 Console.WriteLine($"[Happy count: {happyCount}, Sad count: {sadCount}]");
  47.             }
  48.             else
  49.             {
  50.                 Console.WriteLine($"Happiness index: {happyIndex:F2} :(");
  51.                 Console.WriteLine($"[Happy count: {happyCount}, Sad count: {sadCount}]");
  52.             }
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement