コード例 #1
0
        /// <summary>
        /// A simplest way to render statistic in console
        /// </summary>
        /// <param name="textStatistic"></param>
        public void renderInConsole(TextStatistic textStatistic)
        {
            textStatistic.calculateStatistic();

            foreach (var letter in textStatistic.Letters)
            {
                Console.WriteLine("Letter {0},  repeats {1}", letter.Key, letter.Value);
            }

            Console.WriteLine("Common Letter: {0},  repeats {1}", textStatistic.CommonLetter.Key, textStatistic.CommonLetter.Value);
            Console.WriteLine("Common Word: {0},  repeats {1}", textStatistic.CommonWord.Key, textStatistic.CommonWord.Value);
            Console.WriteLine("Common Prefix: {0},  repeats {1}", textStatistic.CommonPrefix.Key, textStatistic.CommonPrefix.Value);
            Console.WriteLine("Capitalized Letter: {0}", textStatistic.CapitalizedLetter);
        }
コード例 #2
0
        static void Main(string[] args)
        {
            string downloadUrl = "https://ringba-test-html.s3-us-west-1.amazonaws.com/TestQuestions/output.txt";

            using (var client = new WebClient())
            {
                client.DownloadFile(new System.Uri(downloadUrl), "output.txt");
            }
            var stat = new TextStatistic();

            using (var streamReader = new StreamReader(@"output.txt"))
            {
                while (streamReader.Peek() >= 0)
                {
                    stat.AddNextChar(Convert.ToChar(streamReader.Read()));
                }
            }

            var render = new StatisticRenderer();

            render.renderInConsole(stat);
        }