Problem Statement
In this problem we will use the terms XHTML and CSS. They do not match the real-world XHTML and CSS standards exactly. Read the problem statement to clarify the meanings of these terms in the problem context.
You are given a
- tags ::= tag | tag tags
- tagContent ::= EMPTY | tags
- tag ::= <TAG id='ID' style='color:COLOR'>tagContent</TAG>
- EMPTY means an empty string,
- TAG is one of the strings "b", "u", "i", which are called tag names.
- ID means unique non-empty tag identifier containing only lowercase letters,
- COLOR is one of the following seven standard colors: "black", "blue", "gray", "green", "red", "white", "yellow".
We will say that each tag is assigned the specified color. For example, if tags = "<b id='x' style='color:white'><u id='y' style='color:red'></u><u id='z' style='color:red'></u></b>", then the tag with id='x' is assigned the color white, and the tags with id='y' and id='z' are assigned the color red.
You decided to extract the information about assigned colors to CSS rules. Each CSS rule looks like "selector {color:COLOR;}" and assigns a specific color to one or more tags. In this problem we will accept only two types of selectors:
- "#id" â means that CSS rule will be applied to the tag with the given id (example, "#x").
- "#id tagName" â means that CSS rule will be applied to all tags with the specified tag name which are the strict descendants of the tag with the given id (example, "#x u").
Return the minimal number of CSS rules you need to assign the proper color to each tag.
Definition
- Class:
- CssRules
- Method:
- getMinimalCssRuleCount
- Parameters:
- String[]
- Returns:
- int
- Method signature:
- int getMinimalCssRuleCount(String[] xthml)
- (be sure your method is public)
Constraints
- xhtml will contain between 1 and 50 elements, inclusive.
- Each element of xhtml will contain between 1 and 50 characters, inclusive.
- The concatenation of all elements of xhtml will satisfy the grammar given in the problem statement and conditions given after it.
Examples
{""}
Returns: 1
Use only the rule "#x {color:red;}".
{"","", "",""}
Returns: 2
Use two rules "#x {color:red;}" and "#x b {color:red;}".
{"", "", "", "", "", "", "", ""}
Returns: 3
{"", "", "", "", "", "", "", ""}
Returns: 4
{"", ""}
Returns: 2
{""}
Returns: 1
{""}
Returns: 1
{""}
Returns: 1
{""}
Returns: 1
{"",""}
Returns: 3
{""}
Returns: 5
{"","","u><","u id='e' style","='color:red'><","/u>",""}
Returns: 10
{"<","/b>"}
Returns: 11
{"<","b id='o' style='color:y","ellow'><","/u>","<","u id='l' style='color:g","reen'><","u id='j' style='color:y","ellow'><","/u><","u id='d' style='color:g","ray'>"}
Returns: 15
{"","","","","","","","i>",""}
Returns: 22
{""}
Returns: 1
{"",""}
Returns: 3
{"",""}
Returns: 4
{"<","u id='e' style='color:red'>"}
Returns: 4
{"","b>"}
Returns: 5
{"<","b id='d' style='color:","white'>","","b>"}
Returns: 7
{"",""}
Returns: 3
{""}
Returns: 5
{"<","u id='h' style='color:red'>"}
Returns: 6
{"<","b id='b' style='color:white'>","b>"}
Returns: 9
{"<","/b>",""}
Returns: 13
{"","","","u>","","u>","","","","u>"}
Returns: 8
{"<","/u>"}
Returns: 9
{"",""}
Returns: 7
{"","u><","u id='d' style='color:green'>"}
Returns: 13
{"","","<","/b>","b>",""}
Returns: 18
{"","","","","","","","b>"}
Returns: 18
{"","","","<","/u>"}
Returns: 19
{"","","u>","<","/u>"}
Returns: 19
{"<","/b><","b id='d' style='color:yellow'>","b>",""}
Returns: 25
{"<","b id='g' style='color:blue'>","b>"}
Returns: 17
{"","<","u id='r' style='color:","black'><","i id='z' style='color:","black'>","i><","u id='k' style='color:","blue'>","","<","/u>"}
Returns: 12
{"<","/u>","i>","<","/i>"}
Returns: 7
{"","i>","","i><","/u><","/i><","i id='c' style='color:gray'>"}
Returns: 11
{"","<","/b><","b id='n' style='color:gray'>",""}
Returns: 14
{"","<","/b>"}
Returns: 16
{"","<","b id='xa' style='color:white'",">","<","u id='q' style='color:yellow'",">","<","/i>"}
Returns: 18
{"<","/b>","b><","b id='y' style='color:white'",">","b><","b id='e' style='color:yellow","'>"}
Returns: 29
{"","","<","/u>","i>","","i>"}
Returns: 23
{"","<","/u><","/i>","u>",""}
Returns: 33
{"","","","","","","","u><","/b>"}
Returns: 20
{"<","b id='tb' style='color:green'><","/b>"}
Returns: 11
{"","u>","b>"}
Returns: 15
{"","","<","/b><","/b>",""}
Returns: 35
{"<","/b>","","","b>"}
Returns: 30
{"","<","u id='r' style='color:green'>","<","/u>"}
Returns: 30
{"","<","/b><","b id='ha' style='color:blue'>","b>","<","/b>","b>","<","b id='c' style='color:blue'>"}
Returns: 24
{"<","u id='ua' style='color:black'>","","<","u id='w' style='color:black'>","u>",""}
Returns: 22
{"","b><","b id='ga' style='color:green'>","<","b id='l' style='color:green'>","b>",""}
Returns: 27
{"","","","","u>","b>","","",""}
Returns: 22
{"<","u id='fb' style='color:black'><","/u>","<","u id='qa' style='color:black'>","u>"}
Returns: 3
{"","","<","/b>","<","b id='t' style='color:white'>","",""}
Returns: 32
{"","<","/i>","","u>"}
Returns: 23
{"","","","<","u id='sa' style='color:white'>","<","/u>","<","/u>"}
Returns: 29
{"","<","b id='u' style='color:white'><","b id='wb' style='color:yellow'><","b id='ba' style='color:white'>","","<","/b>","b>"}
Returns: 40
{"","","i><","/b>","","","i><","i id='k' style='color:white'><","/u>"}
Returns: 39
{"<","/b><","/b>","","b>"}
Returns: 17
{"<","u id='qc' style='color:black'><","/u>","<","/i>","","","i><","i id='b' style='color:black'>"}
Returns: 4
{"","","<","/u><","/u><","u id='ma' style='color:red'>","","",""}
Returns: 37
{"","","","","u>","","u>","","","u>","b>"}
Returns: 3
{"","b>","","","","b>","","b>"}
Returns: 24
{"","i><","i id='bb' style='color:yellow'>","i><","/b>","i>"}
Returns: 35
{"","<","u id='ua' style='color:yellow'><","/u>","","<","/u>",""}
Returns: 49
{"","","","","","","u><","u id='rb' style='color:black'>","",""}
Returns: 5
{"","","u>","b>",""}
Returns: 26
{"<","b id='xa' style='color:white'>","","u><","/u><","u id='bb' style='color:white'>","u>","b>"}
Returns: 35
{"","<","u id='ld' style='color:black'><","/u>","","u>","","u>",""}
Returns: 4
{"<","b id='ia' style='color:green'>","","","b>"}
Returns: 48
{"","","","<","/i><","/b>","u>","i>",""}
Returns: 19
{"","","<","b id='ca' style='color:green'><","b id='nb' style='color:gray'><","b id='pa' style='color:red'>","","","","b>","b>"}
Returns: 34
{"","","","","<","/u>","<","i id='j' style='color:blue'>","","b>"}
Returns: 43
{"<","b id='oa' style='color:gray'><","/u><","/u>","","",""}
Returns: 33
{"<","i id='la' style='color:green'><","u id='fd' style='color:green'>","","<","/i>","<","/i><","/b>",""}
Returns: 35
{"<","u id='na' style='color:white'>","<","u id='kb' style='color:white'><","/u><","/u>","","","u>"}
Returns: 35
{"<","u id='y' style='color:gray'>","","i>","i>","","u>","",""}
Returns: 35
{"","","","","<","b id='ob' style='color:black'>","b>","<","/b>","","b>","b>"}
Returns: 2
{"","","","","b>","<","/b><","u id='lb' style='color:yellow'>","u>",""}
Returns: 29
{"","<","b id='ba' style='color:green'>","","b>"}
Returns: 49
{"<","b id='za' style='color:gray'><","b id='sa' style='color:blue'><","b id='tb' style='color:blue'><","b id='ac' style='color:gray'>","","","b>","","b>"}
Returns: 27
{"<","i id='xa' style='color:green'>","<","/u>","","","",""}
Returns: 25
{"","","<","/b><","/b><","b id='ma' style='color:red'>","b>","","b>"}
Returns: 35
{"","","","i>","","","","u>"}
Returns: 11
{"<","b id='ia' style='color:red'>","","u><","u id='yc' style='color:red'><","/u>","u><","u id='q' style='color:red'>"}
Returns: 21
{"","","","","","",""}
Returns: 49
{"","","","","<","b id='ea' style='color:black'>","","","b>","","","","b>"}
Returns: 2
{"<","/u>","","u>","u>","","<","b id='s' style='color:yellow'>","u>",""}
Returns: 48
{"","","u>","<","/u>"}
Returns: 44
{"<","u id='i' style='color:green'>","","","u>","","","b>","u>","b>"}
Returns: 14
{"","","","","<","u id='n' style='color:red'><","b id='f' style='color:red'>"}
Returns: 30
{"","","","<","b id='ja' style='color:black'>","u><","/b>","","u>","","u>","b>","u>"}
Returns: 5
{"<","/u>","b>",""}
Returns: 23
{"<","i id='p' style='color:gray'>","i>","i>","u>","","<","/i>"}
Returns: 24
{"","","<","i id='aa' style='color:black'>","","","","i>"}
Returns: 4
{"","b>","","<","/b><","b id='a' style='color:blue'>"}
Returns: 40
{"<","u id='z' style='color:blue'>","","<","/u>","<","/b><","/u>","<","/u>"}
Returns: 18
{"<","b id='i' style='color:yellow'><","b id='o' style='color:green'>","<","b id='xa' style='color:gray'>","<","b id='ob' style='color:green'>","b>","","b><","/b>","b>","<","/b><","/b>"}
Returns: 55
{"","","<","/u><","u id='ra' style='color:green'>","u>","","","",""}
Returns: 50
{"","","<","/u><","/u>","u>","<","/u>"}
Returns: 42
{"<","/b><","/b><","/b>","","b>",""}
Returns: 31
{"<","u id='l' style='color:green'>","<","b id='ra' style='color:black'>","<","/u>","","","","u><","u id='c' style='color:yellow'>"}
Returns: 51
{""}
Returns: 1
{"", "<", "/i>", "", "", "", "", "<", "/i>", "", "", "" }
Returns: 30
{"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" }
Returns: 20
{"", "", "", "", "", "", "", "", "", "<", "/u>", "" }
Returns: 7
{"", "i>", "i><", "i id='n' style='color:black'>" }
Returns: 12
{"", "", "", "", "", "", "", "", "", "", "" }
Returns: 4
{"" }
Returns: 4
{"" }
Returns: 4
{"", "", "", "", "", "" }
Returns: 3
{"", "", "", "", "", "", "" }
Returns: 3
{"<", "b id='w' style='color:yellow'>", "<", "b id='bl' style='color:yellow'>", "b>", "", "b>", "", "b>", "" }
Returns: 42
{"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" }
Returns: 3
{"", "", "u><", "/i>", "", "i>" }
Returns: 29
{"", "", "", "", "", "", "", "" }
Returns: 8
{"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" }
Returns: 4
{"<", "/b><", "/b><", "/i>" }
Returns: 30
{"", "<", "/i>" }
Returns: 22
{"", "" }
Returns: 3
{"", "", "", "u>", "" }
Returns: 44