Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.49 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace Защита_14_лабы
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             StreamReader R = new StreamReader("in.txt");
  15.             //string readString = R.ReadLine();
  16.  
  17.             List<string> Sentences = new List<string>();
  18.  
  19.             char[] punctuation = new char[] { '.', '!', '?' };
  20.  
  21.             string temp_String = "";
  22.  
  23.             //Console.WriteLine(Convert.ToString((char)R.Read()));
  24.  
  25.             while (!R.EndOfStream)
  26.             {
  27.                 string readStr = Convert.ToString((char)R.Read());
  28.                 if (readStr == "\r")
  29.                 {
  30.                     temp_String += " ";
  31.                     R.Read();
  32.                     continue;
  33.                 }
  34.                 if (readStr.IndexOfAny(punctuation) == -1)
  35.                 {
  36.                     temp_String += readStr;
  37.                 }
  38.                 else
  39.                 {
  40.                     temp_String += readStr;
  41.                     Sentences.Add(temp_String);
  42.                     temp_String = "";
  43.                 }
  44.             }
  45.  
  46.  
  47.             //foreach (char symbol in readString)
  48.             //{
  49.             //    if (symbol.ToString().IndexOfAny(punctuation) == -1)
  50.             //    {
  51.             //        temp_String += symbol;
  52.             //    }
  53.             //    else
  54.             //    {
  55.             //        temp_String += symbol;
  56.             //        Sentences.Add(temp_String);
  57.             //        temp_String = "";
  58.             //    }
  59.  
  60.             //}
  61.  
  62.             int numMaxSentences = 0;
  63.             int lengthMaxSentences = 0;
  64.             //string currentSentences;
  65.  
  66.             for (int i = 0; i < Sentences.Count; i++)
  67.             {
  68.                 //currentSentences = Sentences[i];
  69.              if (Sentences[i].Length > lengthMaxSentences)
  70.                 {
  71.                     numMaxSentences = i;
  72.                     lengthMaxSentences = Sentences[i].Length;
  73.                 }  
  74.             }
  75.  
  76.             Console.WriteLine($"Максимальное предложение: {Sentences[numMaxSentences]}");
  77.             Console.WriteLine($"Номер максимального предложения: {numMaxSentences + 1}");
  78.             Console.WriteLine($"Длина максимального предложения: {lengthMaxSentences}");
  79.  
  80.         }
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement