Last active
July 27, 2018 01:32
-
-
Save codewisdom/9c2136050195841170ad4bea528179a7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using System.IO; | |
namespace greedymatch | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
List<int> a = new List<int>() { 2, 8, 5, 4, 2, 5 }; | |
List<int> b = new List<int>() { 3, 4, 6, 5, 1, 5 }; | |
greedyMatch(a, b); | |
Console.ReadKey(); | |
} | |
static void greedyMatch(List<int> inputA, List<int> inputB) | |
{ | |
Dictionary<int, int> result = new Dictionary<int, int>(); | |
foreach (int a in inputA) | |
{ | |
for (int x = 0; x < inputB.Count; x++) | |
{ | |
if (a == inputB[x]) | |
{ | |
if (!result.ContainsKey(x)) | |
{ | |
result.Add(x, a); | |
break; | |
} | |
} | |
} | |
} | |
foreach(int a in result.Values) | |
{ | |
Console.Write("{0}, ", a); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment