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;
- //You will receive an integer list on the first line of the input (space-separated). Leave the first, middle and last elements as they //are. For every other element, exchange it with its opposite indexed element (list[1] list[length-2] and so on…). After that, print //the list on the console (space-separated).
- namespace Flip_List_Sides
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<int> input = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
- if (input.Count % 2 ==1)
- {
- for (int i = 1; i < input.Count / 2; i++)
- {
- int temp = input[i];
- input[i] = input[input.Count - (i + 1)];
- input[input.Count - (i + 1)] = temp;
- }
- }
- else if(input.Count % 2 == 0)
- {
- for (int i = 1; i <= input.Count / 2 - 1; i++)
- {
- int temp = input[i];
- input[i] = input[input.Count - (i + 1)];
- input[input.Count - (i + 1)] = temp;
- }
- }
- Console.WriteLine(string.Join(" ", input));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement