Advertisement
grubcho

Append - Lists

Jun 23rd, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.33 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. //Write a program to append several lists of numbers.
  7. //   Lists are separated by ‘|’.
  8. //   Values are separated by spaces (‘ ’, one or several)
  9. //   Order the lists from the last to the first, and their values from left to right.
  10. //•   Create a new empty list for the results.
  11. //•   Split the input by ‘|’ into array of tokens.
  12. //•   Pass through each of the obtained tokens from tight to left.
  13. //o For each token, split it by space and append all non-empty tokens to the results.
  14. //•   Print the results.
  15.  
  16. namespace Append_list
  17. {
  18.     class Program
  19.     {
  20.         static void Main(string[] args)
  21.         {
  22.             List<string> input = Console.ReadLine().Split('|').ToList();
  23.             input.Reverse();
  24.             List<string> result = new List<string>();
  25.             foreach (var item in input)
  26.             {
  27.                 List<string> nums = item.Split(' ').ToList();
  28.                 foreach (string num in nums)
  29.                 {
  30.                     if (num != "")
  31.                     {
  32.                         result.Add(num);
  33.                     }                        
  34.                 }
  35.             }
  36.             Console.WriteLine(string.Join(" ", result));
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement