Advertisement
cmiN

Inv 2001 R1

Oct 11th, 2011
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.31 KB | None | 0 0
  1.  
  2. Problem Statement
  3.     
  4. ***Note: Please keep programs under 7000 characters in length. Thank you
  5.  
  6.  
  7. Class Name: Prerequisites
  8. Mathod Name: orderClasses
  9. Parameters: String[]
  10. Returns: String[]
  11.  
  12. You are a student at a college with the most unbelievably complex prerequisite
  13. structure ever. To help you schedule your classes, you decided to put together
  14. a program that returns the order in which the classes should be taken.
  15.  
  16. Implement a class Prerequisites which contains a method orderClasses. The
  17. method takes a String[] that contains the classes you must take and returns a
  18. String[] of classes in the order the classes should be taken so that all
  19. prerequisites are met.
  20.  
  21. String[] elements will be of the form (and TopCoder will ensure this):
  22. "CLASS: PRE1 PRE2 ..." where PRE1 and PRE2 are prerequisites of CLASS. CLASS,
  23. PRE1, PRE2, ... consist of a department name (3 or 4 capital letters, A-Z
  24. inclusive) followed by a class number (an integer between 100 and 999,
  25. inclusive). The department name should be immediately followed by the class
  26. number with no additional characters, numbers or spaces (i.e. MATH217). It is
  27. not necessary for a class to have prerequisites. In such a case, the colon is
  28. the last character in the String.
  29.  
  30. You can only take one class at a time, therefore, use the following rules to
  31. determine which class to take :
  32. 1) Any prerequisite class(es) listed for a class must be taken before the class
  33. can be taken.
  34. 2) If multiple classes can be taken at the same time, you take the one with the
  35. lowest number first, regardless of department.
  36. 3) If multiple classes with the same number can be taken at the same time, you
  37. take the department name which comes first in alphabetical order.
  38. 4) If the inputted course schedule has errors, return a String[] of length 0.
  39. There is an error if it is impossible to return the classes in an order such
  40. that all prerequisites are met, or if a prerequisite is a course that does not
  41. have its own entry in the inputted String[].
  42.  
  43. Examples of valid input Strings are:
  44. "CSE111: CSE110 MATH101"
  45. "CSE110:"
  46.  
  47. Examples of invalid input Strings are:
  48. "CS117:" (department name must consist of 3 - 4 capital letters, inclusive)
  49. "cs117:" (department name must consist of 3 - 4 capital letters, inclusive)
  50. "CS9E11:" (department name must be letters only)
  51. "CSE110: " (no trailing spaces allowed)
  52. "CSE110: CSE101 " (no trailing spaces allowed)
  53. "MATH211: MAM2222" (class number to large)
  54. "MATH211: MAM22" (class number to small)
  55. "ENGIN517: MATH211" (department name to large)
  56.  
  57. Here is the method signature (be sure your method is public):
  58. String[] orderClasses(String[] classSchedule);
  59.  
  60. TopCoder will make sure classSchedule contains between 1 and 20 Strings,
  61. inclusive, all of the form above. The Strings will have between 1 and 50
  62. characters, inclusive. TopCoder will check that the syntax of the Strings are
  63. correct: The Strings will contain a valid class name, followed by a colon,
  64. possibly followed by a series of unique prerequisite classes separated by
  65. single spaces. Also, TopCoder will ensure that each class has at most one
  66. entry in the String[].
  67.  
  68. Examples:
  69. If classSchedule={
  70. "CSE121: CSE110",
  71. "CSE110:",
  72. "MATH122:",
  73. }
  74. The method should return: {"CSE110","CSE121","MATH122"}
  75.  
  76. If classSchedule={
  77. "ENGL111: ENGL110",
  78. "ENGL110: ENGL111"
  79. }
  80. The method should return: {}
  81.  
  82. If classSchedule=[
  83. "ENGL111: ENGL110"
  84. }
  85. The method should return: {}
  86.  
  87. If classSchedule={
  88. "CSE258: CSE244 CSE243 INTR100"
  89. "CSE221: CSE254 INTR100"
  90. "CSE254: CSE111 MATH210 INTR100"
  91. "CSE244: CSE243 MATH210 INTR100"
  92. "MATH210: INTR100"
  93. "CSE101: INTR100"
  94. "CSE111: INTR100"
  95. "ECE201: CSE111 INTR100"
  96. "ECE111: INTR100"
  97. "CSE243: CSE254"
  98. "INTR100:"
  99. }
  100. The method should return:
  101. {"INTR100","CSE101","CSE111","ECE111","ECE201","MATH210","CSE254","CSE221","CSE2
  102. 43","CSE244","CSE258"}
  103. Definition
  104.     
  105. Class:
  106. Prerequisites
  107. Method:
  108. orderClasses
  109. Parameters:
  110. vector <string>
  111. Returns:
  112. vector <string>
  113. Method signature:
  114. vector <string> orderClasses(vector <string> param0)
  115. (be sure your method is public)
  116.     
  117.  
  118. This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
  119.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement