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 _07_happinessIndex
- {
- class happinessIndex
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- Regex happyPattern = new Regex(@"(:\)|:D|;\)|:\*|:]|;]|:}|;}|\(:|\*:|c:|\[:|\[;)");
- Regex sadPattern = new Regex(@"(:\(|D:|;\(|:\[|;\[|:\{|;\{|\):|:c|\]:|\];)");
- string[] happy = happyPattern.Matches(input)
- .Cast<Match>()
- .Select(h => h.Value)
- .ToArray();
- string[] sad = sadPattern.Matches(input)
- .Cast<Match>()
- .Select(s => s.Value)
- .ToArray();
- double happyCount = happy.Count();
- double sadCount = sad.Count();
- double happyIndex = happyCount / sadCount;
- if (happyIndex >= 2.00)
- {
- Console.WriteLine($"Happiness index: {happyIndex:F2} :D");
- Console.WriteLine($"[Happy count: {happyCount}, Sad count: {sadCount}]");
- }
- else if(happyIndex > 1.00)
- {
- Console.WriteLine($"Happiness index: {happyIndex:F2} :)");
- Console.WriteLine($"[Happy count: {happyCount}, Sad count: {sadCount}]");
- }
- else if(happyIndex == 1.00)
- {
- Console.WriteLine($"Happiness index: {happyIndex:F2} :|");
- Console.WriteLine($"[Happy count: {happyCount}, Sad count: {sadCount}]");
- }
- else
- {
- Console.WriteLine($"Happiness index: {happyIndex:F2} :(");
- Console.WriteLine($"[Happy count: {happyCount}, Sad count: {sadCount}]");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement