TopCoder problem "Logger" used in TCO '03 Round 1 (Division I Level Two)



Problem Statement

    Most large software packages have some logging options built in to them. Many times there are different logging levels that can be set. Your task is to write a class to perform this logging. Your class will be given a number of messages, each associated with some priority. If the priority of a message is equal to or higher than the logging priority, then you should log that message, otherwise it should be ignored. You will be given a String[], messages, each of whose elements represents a single message, a String[], priorities, each of whose elements represents the priority of the message with the same index, and a String[], precedence, giving the order of the priorities. Element 0 of precedence represents the lowest priority, element 1 the next lowest, and so on. Lastly, you will be given a String, loggingPriority, representing the lowest priority of messages to log. loggingPriority and each element of priorities will be formatted as "<priority>", or "<priority> <num>", where <priority> is an element of precedence and <num> is an integer between 0 and 100, inclusive. If <num> is not present, it is the same as if it were a 0.



You should return a String[] containing all of the messages with sufficiently high priority to be logged, in the order they were given to you. A message has sufficiently high priority to be logged if the corresponding <priority> is higher than that in loggingPriority, or if the corresponding <priority> is the same, and <num> is greater than or equal to that in loggingPriority. Additionally, priorities are case insensitive.



So, if precedence is {"info","DEBUG","error","fatal"}, and loggingPriority is "debug 1", then messages with priorities of "debug 1", "debug 43", "Error", and "fatal 1" would all be logged. Messages with priorities of "debug 0", "debug", "info", and "info 100" would not be logged.
 

Definition

    
Class:Logger
Method:log
Parameters:String[], String[], String[], String
Returns:String[]
Method signature:String[] log(String[] messages, String[] priorities, String[] precedence, String loggingPriority)
(be sure your method is public)
    
 

Constraints

-loggingPriority and each element of priorities will be formatted as "<priority>" or "<priority> <num>"
-Each <priority> in priorities and loggingPriority will be an element of precedence, ignoring case.
-Each <num> in priorities and loggingPriority will be between 0 and 100, inclusive, with no extraneous leading 0's.
-precedence will contain no repeated elements, ignoring case.
-Each element of precedence will contain between 1 and 40 letters ('a'-'z' and 'A'-'Z'), inclusive.
-Each element of messages will contain between 0 and 50 characters, inclusive, each of which will be between ASCII 32 and 126, inclusive.
-priorities and messages will contain the same number of elements.
-priorities, messages, and precedence will each contain between 1 and 50 elements, inclusive.
 

Examples

0)
    
{"in doit()...","n=9","n=13","x=-3","divide by 0",
 "index out of bounds","n=-1","this shouldn't happen","bailing out"}
{"info 3","debug","debug","debug 3","error","ERROR 5","debug 2","critical","fatal 100"}
{"info","debug","exceptional","error","critical","fatal"}
"error 1"
Returns: { "index out of bounds",  "this shouldn't happen",  "bailing out" }
All of the messages with logging level of "error 1" or higher should be logged. Note that the logging level is case insensitive, so "ERROR 5" is the same as "error 5"
1)
    
{"in doit()...","n=9","n=13","x=-3","divide by 0",
 "index out of bounds","n=-1","this shouldn't happen","bailing out"}
{"info 3","debug","debug","debug 3","error","ERROR 5","debug 2","critical","fatal 100"}
{"info","debug","exceptional","error","critical","fatal"}
"debug 2"
Returns: 
{ "x=-3",
 "divide by 0",
 "index out of bounds",
 "n=-1",
 "this shouldn't happen",
 "bailing out" }
2)
    
{"1","2","3",""}
{"A","b","C","d"}
{"a","b","c","D"}
"C"
Returns: { "3",  "" }

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=1816

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=4702&pm=1816

Writer:

lars2520

Testers:

Problem categories:

String Manipulation