fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. public class JobControl
  6. {
  7. public static void Main()
  8. {
  9. List<string> lst = new List<string>();
  10.  
  11. while(true)
  12. {
  13. string line = Console.ReadLine();
  14. if( line == null || line == string.Empty )
  15. {
  16. break;
  17. }
  18.  
  19. lst.Add(line);
  20. }
  21.  
  22. proc(lst);
  23. }
  24.  
  25. private static Dictionary<string, Job> dicJob;
  26.  
  27. private static void proc(List<string> lst)
  28. {
  29. List<Job> jobList = new List<Job>();
  30. foreach(string line in lst)
  31. {
  32. jobList.Add(new Job(line));
  33. }
  34.  
  35. dicJob = new Dictionary<string, Job>();
  36. foreach(Job job in jobList)
  37. {
  38. if( job.parent != null)
  39. {
  40. foreach(string pjob in job.parent)
  41. {
  42. if( dicJob.ContainsKey(pjob) )
  43. {
  44. if( job.priority >= dicJob[pjob].priority + 1 )
  45. {
  46. job.priority = dicJob[pjob].priority + 1;
  47. }
  48. }
  49. else
  50. {
  51. Job tmp = new Job();
  52. tmp.name = pjob;
  53. dicJob.Add(pjob, tmp);
  54. job.priority = tmp.priority + 1;
  55. }
  56. }
  57.  
  58. if( dicJob.ContainsKey(job.name) == false )
  59. {
  60. dicJob.Add(job.name, job);
  61. }
  62. }
  63. else
  64. {
  65. //依存するジョブ無し
  66. if( dicJob.ContainsKey(job.name) == false )
  67. {
  68. dicJob.Add(job.name, job);
  69. }
  70. }
  71. }
  72.  
  73. //出力準備・・・無駄が多いかな
  74. Dictionary<int, string> dicOutput = new Dictionary<int, string>();
  75. int maxPriority = 0;
  76. foreach(string key in dicJob.Keys)
  77. {
  78. int p = dicJob[key].priority;
  79. if( dicOutput.ContainsKey(p) )
  80. {
  81. dicOutput[p] += " "+ dicJob[key].name;
  82. }
  83. else
  84. {
  85. dicOutput.Add(p, dicJob[key].name);
  86. }
  87.  
  88. if( maxPriority < p )
  89. {
  90. maxPriority = p;
  91. }
  92. }
  93.  
  94. //出力
  95. for(int i = 1; i <= maxPriority; i++)
  96. {
  97. string[] tmpArg = dicOutput[i].Trim().Split(' ');
  98. Array.Sort(tmpArg);
  99. Console.WriteLine(string.Join(" ", tmpArg));
  100. }
  101. }
  102.  
  103. private class Job
  104. {
  105. internal int priority { get; set; }
  106. internal string name { get; set; }
  107. internal List<string> parent { get; private set; }
  108.  
  109. internal Job()
  110. {
  111. priority = 1;
  112. name = string.Empty;
  113. parent = null;
  114. }
  115.  
  116. internal Job(string line)
  117. {
  118. priority = 1;
  119.  
  120. if( line.IndexOf(':') == -1 )
  121. {
  122. name = line;
  123. parent = null;
  124. }
  125. else
  126. {
  127. name = line.Split(':')[0].Trim();
  128. parent = new List<string>();
  129.  
  130. string[] dependJob = line.Split(':')[1].Trim().Split(' ');
  131. foreach(string dj in dependJob)
  132. {
  133. parent.Add(dj.Trim());
  134. }
  135. }
  136. }
  137. }
  138. }
  139.  
Success #stdin #stdout 0.02s 131776KB
stdin
1 : 2
3 : 2
stdout
2 3
1