JulianJulianov

05.AssociativeArray-Word Filter

Apr 12th, 2020
387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.06 KB | None | 0 0
  1. 05. Word Filter
  2. Read an array of strings and take only words, whose length is even. Print each word on a new line.
  3. Examples
  4. Input                             Output
  5. kiwi orange banana apple          kiwi
  6.                                   orange
  7.                                   banana
  8.  
  9. pizza cake pasta chips            cake
  10.  
  11. • Read an array of strings
  12. • Filter those whose length is even
  13.  
  14. • Print each word on a new line
  15.  
  16. using System;
  17. using System.Collections.Generic;
  18. using System.Linq;
  19.  
  20. namespace InboxManager
  21. {
  22.   class Program
  23.    {
  24.       static void Main(string[] args)
  25.       {
  26.         var words = Console.ReadLine().Split().Where(x => x.Length % 2 == 0);
  27.            
  28.         foreach (var word in words)
  29.         {
  30.       //    var counter = 0;             //Втори вариант на решение.
  31.       //    foreach (var item in word)
  32.       //    {
  33.       //        counter++;
  34.       //    }        
  35.       //    if (counter % 2 == 0)
  36.       //    {
  37.               Console.WriteLine(word);
  38.       //    }
  39.          }
  40.       }
  41.    }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment