Advertisement
vovanhoangtuan

Couting Diff

Apr 13th, 2020
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.73 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.  
  7. namespace Bai1
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int[] a = { 3, 4, 5, 1, 7, 10, 2};
  14.             Array.Sort(a);
  15.             List<int> res = new List<int>();
  16.  
  17.             int i = 1;
  18.             int currentValue = a[0];
  19.             res.Add(currentValue);
  20.  
  21.             while (i < a.Length )
  22.             {
  23.                 while (currentValue == a[i]) i++;
  24.                 currentValue = a[i];
  25.                 res.Add(currentValue);
  26.                 i++;
  27.             }
  28.            
  29.             Console.WriteLine(res.Count);
  30.         }
  31.  
  32.        
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement