fork(1) download
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. public class Test
  6. {
  7. public static void Main()
  8. {
  9. List<string> l1 = new List<string> { "abc", "abc", "abc", "def" };
  10. List<string> l2 = new List<string> { "abc" };
  11. // Make word counts for l1 and l2
  12. var c1 = l1.GroupBy(x => x).ToDictionary(g => g.Key, g => g.Count());
  13. var c2 = l2.GroupBy(x => x).ToDictionary(g => g.Key, g => g.Count());
  14. // Make a count of the difference between the two
  15. var diff = new Dictionary<string,int>();
  16. foreach (var p in c1) {
  17. int sub;
  18. if (!c2.TryGetValue(p.Key, out sub)) {
  19. sub = 0;
  20. }
  21. diff[p.Key] = p.Value - sub;
  22. }
  23. // Reconstruct the result from counts
  24. var res = diff.SelectMany(p => Enumerable.Repeat(p.Key, p.Value)).ToList();
  25. foreach (var s in res) {
  26. Console.WriteLine(s);
  27. }
  28. }
  29. }
Success #stdin #stdout 0s 29952KB
stdin
Standard input is empty
stdout
abc
abc
def