Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace I5_17
- {
- class Program
- {
- static void Main(string[] args)
- {
- string text = Console.ReadLine();
- int indexSpace = text.IndexOf(' ');
- if (indexSpace != -1)
- {
- string longestWord = text.Substring(0, indexSpace);
- int count = 1;
- int index = text.IndexOf(longestWord, 1);
- while (index != -1)
- {
- count++;
- index = text.IndexOf(longestWord, index + 1);
- }
- while (true)
- {
- indexSpace = text.IndexOf(' ', indexSpace + 1);
- if (indexSpace != -1)
- {
- int tempIndex = text.IndexOf(' ', indexSpace + 1);
- string tempWord = "";
- if (tempIndex != -1)
- {
- tempWord = text.Substring(indexSpace + 1, tempIndex - indexSpace - 1);
- }
- else
- {
- tempWord = text.Substring(indexSpace + 1, text.Length - indexSpace - 1);
- }
- if (tempWord != longestWord)
- {
- int tempCount = 0;
- index = text.IndexOf(tempWord, indexSpace);
- while (index != -1)
- {
- tempCount++;
- index = text.IndexOf(tempWord, index + 1);
- }
- if (tempCount > count)
- {
- longestWord = tempWord;
- count = tempCount;
- }
- }
- }
- else
- {
- Console.WriteLine("Най-срещаната дума е {0}", longestWord);
- Console.WriteLine("Среща се {0} път/и", count);
- break;
- }
- }
- }
- else
- {
- Console.WriteLine("Най-срещаната дума е {0}", text);
- Console.WriteLine("Среща се 1 път");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment