fork(5) download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp1
  8. {
  9. class Program
  10. {
  11.  
  12. static void Main(string[] args)
  13. {
  14. int x;
  15. x=Int32.Parse(Console.ReadLine());
  16. Dictionary<string, int> dict = new Dictionary<string, int>();
  17. List<string> erdos = new List<string>();
  18. List<string> wszystko = new List<string>();
  19. Dictionary<string, List<string>> biblio = new Dictionary<string, List<string>>();
  20.  
  21. for (int i = 0; i < x; i++)
  22. {
  23. string line = Console.ReadLine();
  24. string surname, article;
  25. surname = line.Split(' ')[0];
  26. article = line.Split(' ')[1].Replace('"', new char());
  27. if (biblio.ContainsKey(surname))
  28. {
  29. biblio[surname].Add(article);
  30. }
  31. else
  32. biblio.Add(surname, new List<string>() {article});
  33. }
  34. foreach (var item in biblio)
  35. {
  36. dict.Add(item.Key, -1);
  37. }
  38. if (dict.Keys.Contains("P.Erdos")) dict["P.Erdos"] = 0;
  39. int n = 0;
  40. while(dict.Values.Contains(n))
  41. {
  42. foreach (var it in biblio)
  43. {
  44. if (dict[it.Key] == n)
  45. {
  46. foreach (var item in biblio[it.Key])
  47. {
  48. foreach (var surname in biblio.Keys)
  49. {
  50. if (biblio[surname].Contains(item) && !surname.Equals("P.Erdos") && dict[surname] < 0)
  51. {
  52. dict[surname] = n + 1;
  53. }
  54. }
  55. }
  56. }
  57.  
  58. }
  59. n++;
  60. }
  61. //foreach (var item in biblio["P.Erdos"])
  62. //{
  63. // foreach (var surname in biblio.Keys)
  64. // {
  65. // if (biblio[surname].Contains(item) && !surname.Equals("P.Erdos"))
  66. // {
  67. // dict[surname] = 1;
  68. // }
  69. // }
  70. //}
  71.  
  72. //foreach (var item in dict)
  73. //{
  74. // Console.WriteLine(item.Key + " " + item.Value);
  75. //}
  76. var list = dict.Keys.ToList();
  77. list.Sort();
  78. foreach (var item in list)
  79. {
  80. if(dict[item]==-1)
  81. Console.WriteLine(item + ": " + "inf");
  82. else
  83. Console.WriteLine(item+": "+ dict[item]);
  84. }
  85. }
  86. }
  87. }
  88.  
Success #stdin #stdout 0.01s 131648KB
stdin
2
M."Max"Kolonko "Odkrywanie Ameryki"
P.Erdos "Max"
stdout
M."Max"Kolonko: inf
P.Erdos: 0