Advertisement
Rustikus

DistinctList

Jun 27th, 2017
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.02 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace DistinctList
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string input = Console.ReadLine();
  12.             List<long> intList = input.Split(' ').Select(long.Parse).ToList();
  13.             List<int> removeList = new List<int>();
  14.             for (int i = 0; i < intList.Count; i++)
  15.             {
  16.                 for (int j = i; j < intList.Count; j++)
  17.                 {
  18.                     if (intList[i] == intList[j] && i != j)
  19.                     {
  20.                         removeList.Add(j);
  21.                     }
  22.                 }
  23.             }
  24.             removeList.Sort();
  25.             for (int i = removeList.Count - 1; i >= 0; i--)
  26.             {
  27.                 intList.RemoveAt(removeList[i]);
  28.             }
  29.             for (int i = 0; i < intList.Count; i++)
  30.             {
  31.                 Console.Write(intList[i] + " ");
  32.             }
  33.             Console.WriteLine();
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement