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;
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Main(string[] args)
- {
- /*
- * 3. Дана строка текста, в которой слова разделены запятыми. Необходимо:
- - определить количество слов в строке;
- - определить, сколько слов в строке имеют максимальную длину;
- - определить, есть ли в данной строке повторяющиеся слова, и вывести их на экран.
- */
- string min;
- int n = 0;
- string tmp;
- Console.WriteLine("Введите строку :");
- string text = Console.ReadLine();
- Console.WriteLine("Количество слов в строке :");
- string[] words = text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
- Console.WriteLine(words.Length);
- min = words[0];
- for (int i = 1; i < words.Length; i++)
- {
- if (min.Length < words[i].Length)
- {
- min = words[i];
- }
- }
- foreach (string word in words)
- {
- if (word.Length == min.Length)
- {
- n += 1;
- }
- }
- Console.WriteLine("Количество слов с максимальной длинной: " + n);
- Console.WriteLine("Повторяющиеся слова: ");
- for (int i = 0;i < words.Length;i++)
- {
- tmp = words[i];
- for (int j = words.Length-1;j>i;j--)
- {
- if (words[j] == tmp)
- {
- Console.WriteLine(words[j]);
- }
- }
- }
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement