Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.35 KB | None | 0 0
  1. class Program
  2.     {
  3.         static void Main(string[] args)
  4.         {
  5.             string line = "start";
  6.             int count = 0;
  7.             List<string> linebox = new List<string>();
  8.             List<string> wordbox = new List<string>();
  9.             try
  10.             {
  11.                 StreamReader sr = new StreamReader(@"C:\Users\Home\source\repos\ConsoleApp1\lul.txt");
  12.                 while(line != null)
  13.                 {
  14.                     line = sr.ReadLine();
  15.                     if(line == null)
  16.                     {
  17.                         continue;
  18.                     }
  19.                     else
  20.                     {
  21.                         linebox.Add(line);
  22.                     }
  23.  
  24.                 }
  25.                 sr.Close();
  26.             }
  27.             catch(Exception ex)
  28.             {
  29.                 Console.WriteLine(ex.Message);
  30.             }
  31.             foreach(string s in linebox)
  32.             {
  33.                 wordbox.AddRange(s.Split(' '));
  34.             }
  35.             foreach(string s in wordbox)
  36.             {
  37.                 if(s.Length <= 4)
  38.                 {
  39.                     count++;
  40.                 }
  41.             }
  42.  
  43.             Console.WriteLine("Количество слов, в которых не больше 4 букв: {0}", count);
  44.             Console.ReadLine();
  45.            
  46.         }
  47.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement