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;
- namespace ArrayStuff2
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] A = {1,1,1,2,3,4,2,3,4,5,3,6};
- int[] B = {2,5,8,8,7,9,0};
- foreach (int n in new Uniquelizer(A,B).Uniquelize())
- Console.WriteLine(n);
- }
- }
- class Uniquelizer
- {
- private int uniqueCounter = 0;
- private int[] elementCounters = new int[10];
- public Uniquelizer(int[] first, int[] second)
- {
- countNumbersInArray(first);
- countNumbersInArray(second);
- }
- private void countNumbersInArray(int[] array)
- {
- foreach (int n in array)
- {
- if (elementCounters[n] == 0)
- uniqueCounter++;
- if (elementCounters[n] == 1)
- uniqueCounter--;
- elementCounters[n]++;
- }
- }
- public int[] Uniquelize()
- {
- int[] result = new int[uniqueCounter];
- for (int i = 0, uniqueIndex = 0; i < 10; i++)
- {
- if (elementCounters[i] == 1)
- {
- result[uniqueIndex] = i;
- uniqueIndex++;
- }
- }
- return result;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement