SHARE
TWEET

Test

Simsona86 Sep 11th, 2019 75 in 174 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Text.RegularExpressions;
  6.  
  7. namespace ConsoleApp1
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             var result = string.Empty;
  14.             var webClient = new System.Net.WebClient();
  15.             result = webClient.DownloadString("https://ringba-test-html.s3-us-west-1.amazonaws.com/TestQuestions/output.txt");
  16.             string[] textArray = Regex.Split(result, @"(?<!^)(?=[A-Z])");
  17.      
  18.             Dictionary<string, int> maxCapitalLetters = searchForMaxCapitalLetters(textArray);
  19.             Dictionary<string, int> maxPrefixFirstTowCharacter = searchMaxPrefixFirstTowCharacter(textArray);
  20.  
  21.  
  22.             var lengthText = result.Length;
  23.             var countUppercase = textArray.Length;
  24.  
  25.             var firstCapital = maxCapitalLetters.First();
  26.             var word = firstCapital.Key;
  27.             var valueWord = firstCapital.Value;
  28.  
  29.             var firstPrefix = maxPrefixFirstTowCharacter.First();
  30.             var prefix = firstPrefix.Key;
  31.             var valuePrefix = firstPrefix.Value;
  32.  
  33.             Console.WriteLine($"Length of text - {lengthText}");
  34.             Console.WriteLine($"Number of capital letters - {countUppercase}");
  35.             Console.WriteLine($"Word: {word} - repetitions {valueWord}");
  36.             Console.WriteLine($"Prefix: {prefix} - repetitions {valuePrefix}");
  37.         }
  38.  
  39.         static Dictionary<string, int> searchForMaxCapitalLetters(string[] text)
  40.         {
  41.             Dictionary<string, int> maxCapitalLetters = new Dictionary<string, int>();
  42.             foreach (var rep in text)
  43.             {
  44.                 if (maxCapitalLetters.ContainsKey(rep))
  45.                 {
  46.                     maxCapitalLetters[rep]++;
  47.                 }
  48.                 else
  49.                 {
  50.                     maxCapitalLetters[rep] = 1;
  51.                 }
  52.             }
  53.             maxCapitalLetters = maxCapitalLetters
  54.                 .OrderByDescending(x => x.Value)
  55.                 .ToDictionary(x => x.Key, x => x.Value);
  56.  
  57.             return maxCapitalLetters;
  58.         }
  59.  
  60.         static Dictionary<string, int> searchMaxPrefixFirstTowCharacter(string[] text)
  61.         {
  62.             Dictionary<string, int> maxPrefixFirstTowCharacter = new Dictionary<string, int>();
  63.  
  64.             foreach (var rep in text)
  65.             {
  66.                 if (rep.Length > 2)
  67.                 {
  68.                     string firstTowChars = rep.Substring(0, 2);
  69.                     if (maxPrefixFirstTowCharacter.ContainsKey(firstTowChars))
  70.                     {
  71.                         maxPrefixFirstTowCharacter[firstTowChars]++;
  72.                     }
  73.                     else
  74.                     {
  75.                         maxPrefixFirstTowCharacter[firstTowChars] = 1;
  76.                     }
  77.                 }
  78.             }
  79.             maxPrefixFirstTowCharacter = maxPrefixFirstTowCharacter
  80.                 .OrderByDescending(x => x.Value)
  81.                 .ToDictionary(x => x.Key, x => x.Value);
  82.  
  83.             return maxPrefixFirstTowCharacter;
  84.         }
  85.     }
  86. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top