Sybatron

I5-17

Mar 25th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.48 KB | None | 0 0
  1. using System;
  2.  
  3. namespace I5_17
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string text = Console.ReadLine();
  10.             int indexSpace = text.IndexOf(' ');
  11.  
  12.             if (indexSpace != -1)
  13.             {
  14.                 string longestWord = text.Substring(0, indexSpace);
  15.                 int count = 1;
  16.                 int index = text.IndexOf(longestWord, 1);
  17.                 while (index != -1)
  18.                 {
  19.                     count++;
  20.                     index = text.IndexOf(longestWord, index + 1);
  21.                 }
  22.  
  23.                 while (true)
  24.                 {
  25.                     indexSpace = text.IndexOf(' ', indexSpace + 1);
  26.                     if (indexSpace != -1)
  27.                     {
  28.                         int tempIndex = text.IndexOf(' ', indexSpace + 1);
  29.                         string tempWord = "";
  30.                         if (tempIndex != -1)
  31.                         {
  32.                             tempWord = text.Substring(indexSpace + 1, tempIndex - indexSpace - 1);
  33.                         }
  34.                         else
  35.                         {
  36.                             tempWord = text.Substring(indexSpace + 1, text.Length - indexSpace - 1);
  37.                         }
  38.  
  39.                         if (tempWord != longestWord)
  40.                         {
  41.                             int tempCount = 0;
  42.                             index = text.IndexOf(tempWord, indexSpace);
  43.                             while (index != -1)
  44.                             {
  45.                                 tempCount++;
  46.                                 index = text.IndexOf(tempWord, index + 1);
  47.                             }
  48.                             if (tempCount > count)
  49.                             {
  50.                                 longestWord = tempWord;
  51.                                 count = tempCount;
  52.                             }
  53.                         }
  54.                     }
  55.                     else
  56.                     {
  57.                         Console.WriteLine("Най-срещаната дума е {0}", longestWord);
  58.                         Console.WriteLine("Среща се {0} път/и", count);
  59.                         break;
  60.                     }
  61.                 }
  62.             }
  63.             else
  64.             {
  65.                 Console.WriteLine("Най-срещаната дума е {0}", text);
  66.                 Console.WriteLine("Среща се 1 път");
  67.             }
  68.         }
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment