Advertisement
Guest User

17

a guest
Dec 8th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.57 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3. using System.IO;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8.  
  9. namespace TFYA_lab17
  10. {
  11.     class Program
  12.     {
  13.         static void Main(string[] args)
  14.         {
  15.             string text = "";
  16.             string[] sentences;
  17.             int counter = 0;
  18.             using (StreamReader sr = new StreamReader("D:\\Нужное\\ТФЯ\\lab17\\var5.txt",Encoding.UTF8))
  19.             {
  20.                 text = sr.ReadToEnd();
  21.             }
  22.             sentences = Regex.Split(text, @"\.");
  23.             int[] amounts = new int[sentences.Length];
  24.             for(int k = 0;k<sentences.Length;k++)
  25.             {
  26.                 if(Regex.Matches(sentences[k],@"\s\s+").Count>0)
  27.                 {
  28.                     counter++;
  29.                 }
  30.                 string[] splits = sentences[k].ToLower().Split(' ');
  31.                 for(int i = 0;i<splits.Length;i++)
  32.                 {
  33.                     splits[i].Replace(' ', '\u0000');
  34.                 }
  35.                 int localCounter = 0, counter2 = 0;
  36.                 for (int i = 0;i<splits.Length-1;i++)
  37.                 {
  38.                     for(int j = i+1;j<splits.Length;j++)
  39.                     {
  40.                         if(splits[i]==splits[j])
  41.                         {
  42.                             localCounter++;
  43.                         }
  44.                     }
  45.                     if(localCounter>counter2)
  46.                     {
  47.                         counter2 = localCounter;
  48.                     }
  49.                     localCounter = 0;
  50.                 }
  51.                 amounts[k] = counter2;
  52.             }
  53.             int maxAmount = 0;
  54.             int place = 0;
  55.             for(int i = 0;i<amounts.Length;i++)
  56.             {
  57.                 if(amounts[i]>maxAmount)
  58.                 {
  59.                     maxAmount = amounts[i];
  60.                     place = i + 1;
  61.                 }
  62.             }
  63.             if(maxAmount>0)
  64.             {
  65.                 Console.WriteLine($"Максимальное число одинаковых слов находится в {place} предложении. Количество повторений - {maxAmount}");
  66.             }
  67.             else
  68.             {
  69.                 Console.WriteLine("Повторения отсутствуют");
  70.             }
  71.             Console.WriteLine("Количество предложений, в которых интервал между словами больше единицы - " + counter);
  72.         }
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement