Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- //Write a program to append several lists of numbers.
- // Lists are separated by ‘|’.
- // Values are separated by spaces (‘ ’, one or several)
- // Order the lists from the last to the first, and their values from left to right.
- //• Create a new empty list for the results.
- //• Split the input by ‘|’ into array of tokens.
- //• Pass through each of the obtained tokens from tight to left.
- //o For each token, split it by space and append all non-empty tokens to the results.
- //• Print the results.
- namespace Append_list
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<string> input = Console.ReadLine().Split('|').ToList();
- input.Reverse();
- List<string> result = new List<string>();
- foreach (var item in input)
- {
- List<string> nums = item.Split(' ').ToList();
- foreach (string num in nums)
- {
- if (num != "")
- {
- result.Add(num);
- }
- }
- }
- Console.WriteLine(string.Join(" ", result));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement