fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5.  
  6. static class Program
  7. {
  8. static List<string> authors = new List<string> { "A", "B", "C", "A" };
  9.  
  10. static void Main()
  11. {
  12. var edge = new List<int> { 0, 1, 2, 3 };
  13. foreach (var duplicate in authors.GetDuplicates())
  14. {
  15. for (int j = 0; j < edge.Count; j++)
  16. {
  17. for (int k = 0; k < duplicate.Count - 1; k++)
  18. {
  19. if (edge[j] == duplicate[k])
  20. {
  21. edge[j] = duplicate[k + 1];
  22. }
  23. }
  24. }
  25. }
  26.  
  27. Debug.Assert(edge.SequenceEqual(new[] { 3, 1, 2, 3 }));
  28. foreach (var e in edge)
  29. {
  30. Console.WriteLine(e);
  31. }
  32. }
  33.  
  34. public static List<List<int>> GetDuplicates(this IList<string> source)
  35. {
  36. HashSet<string> itemsSeen = new HashSet<string>();
  37. HashSet<string> itemsYielded = new HashSet<string>();
  38. List<List<int>> duplicates = new List<List<int>>();
  39. List<int> dupLow = new List<int>();
  40. HashSet<int> temp = new HashSet<int>();
  41.  
  42. int c = 0;
  43.  
  44. foreach (string item in source)
  45. {
  46. if (!itemsSeen.Add(item))
  47. {
  48. if (itemsYielded.Add(item))
  49. {
  50. if (item != "-")
  51. {
  52. int w = 0;
  53.  
  54. for (int j = 0; j < authors.Count; j++)
  55. {
  56. if (authors[j] == authors[c])
  57. {
  58. temp.Add(w);
  59. }
  60. w++;
  61. }
  62.  
  63. dupLow = new List<int>(temp);
  64. duplicates.Add(dupLow);
  65. temp.Clear();
  66. }
  67. }
  68. }
  69. c++;
  70. }
  71. return duplicates;
  72. }
  73. }
  74.  
Success #stdin #stdout 0.05s 34944KB
stdin
Standard input is empty
stdout
3
1
2
3