Advertisement
ElliasBLR

LabRequest5

Oct 27th, 2020
826
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.32 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication1
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.  
  13.             /*
  14.              * 3.   Дана строка текста, в которой слова разделены запятыми. Необходимо:
  15.             - определить количество слов в строке;
  16.             - определить, сколько слов в строке имеют максимальную длину;
  17.             - определить, есть ли в данной строке повторяющиеся слова, и вывести их на экран.
  18.  
  19.              */
  20.  
  21.            
  22.             string min;
  23.             int n = 0;
  24.             string tmp;
  25.             Console.WriteLine("Введите строку :");
  26.             string text = Console.ReadLine();
  27.             Console.WriteLine("Количество слов в строке :");
  28.             string[] words = text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  29.             Console.WriteLine(words.Length);
  30.             min = words[0];
  31.            
  32.             for (int i = 1; i < words.Length; i++)
  33.             {
  34.  
  35.                 if (min.Length <  words[i].Length)
  36.                 {
  37.  
  38.                     min = words[i];
  39.                    
  40.                 }
  41.             }
  42.            
  43.             foreach (string word in words)
  44.             {  
  45.                 if (word.Length == min.Length)
  46.                 {
  47.                     n += 1;
  48.                    
  49.                 }
  50.  
  51.             }
  52.             Console.WriteLine("Количество слов с максимальной длинной: " + n);
  53.             Console.WriteLine("Повторяющиеся слова: ");
  54.            
  55.             for (int i = 0;i < words.Length;i++)
  56.             {
  57.                 tmp = words[i];
  58.                 for (int j = words.Length-1;j>i;j--)
  59.                 {
  60.  
  61.                     if (words[j] == tmp)
  62.                     {
  63.                         Console.WriteLine(words[j]);
  64.                     }
  65.                    
  66.  
  67.                 }
  68.                
  69.                
  70.                
  71.  
  72.             }
  73.            
  74.  
  75.  
  76.  
  77.  
  78.             Console.ReadKey();
  79.  
  80.  
  81.         }
  82.     }
  83. }
  84.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement