Problem Statement
|-O-| |-O-| |-O-| |-O-| |-O-|
Above you see a tiny fraction of our glorious imperial fleet, the Twin Ion Engine starfighters (known as "TIE fighters" for short).
Each TIE fighter consists of two solar array wings ('|'), two wing braces ('-') and one central cabin ('O').
Even though our TIE fighters are clearly superior to the X-wing fighters flown by those pesky rebels, occasionally some TIE fighter will receive some accidental combat damage. Whenever a damaged TIE fighter is recovered, we disasemble it and salvage the parts that are still in working condition. It is now up to you to use these salvaged parts to assemble as many complete TIE fighters as possible.
You are given the
There may also be other characters in salvagedParts. These represent machinery that isn't used in a TIE fighter.
Calculate and return the maximum number of TIE fighters you can assemble from the given parts.
Definition
- Class:
- TIEFighterAssembly
- Method:
- assemble
- Parameters:
- String
- Returns:
- int
- Method signature:
- int assemble(String salvagedParts)
- (be sure your method is public)
Constraints
- salvagedParts will contain between 1 and 50 characters, inclusive.
- Each character of salvagedParts will be one of "|-O=+()*" (quotes for clarity).
Examples
"|-O-|"
Returns: 1
One fully functional TIE fighter.
"||--O"
Returns: 1
The same parts as in the previous example. Again, we can use them to build one TIE fighter.
"|||||-----OOO"
Returns: 2
These parts are enough to build two TIE fighters. We will have one '|', one '-' and one 'O' left over.
"=+()*=+()*=+()*"
Returns: 0
Useless debris that cannot be used in a TIE fighter.
"||+||-||+||-||+||-||+||-"
Returns: 0
We have a lot of solar panels and a lot of wing pylons (and also some '+' that we have no use for). However, we have no central cabins and so we cannot assemble any complete TIE fighters.
"===O|O-O|O-O|O==="
Returns: 1
In this example we have the opposite problem: too many cabins but not enough wing parts to use all of them. We can put together just one single TIE fighter. A lot of material will remain unused.
"|"
Returns: 0
"-"
Returns: 0
"O"
Returns: 0
"|--|"
Returns: 0
"|-O|"
Returns: 0
"|--O"
Returns: 0
"--O|-|"
Returns: 1
"--||||OO|O-O-OO|--|-|O-O|-O"
Returns: 4
"--||-O||-|--O-O---O|-|-O--OO|"
Returns: 4
"|--|O-"
Returns: 1
"|-O---OO|-O-|||-O-|-|--||--||O|-"
Returns: 6
"O|-O--||-|------||---||-||"
Returns: 2
"-O|-OO-||O|--"
Returns: 2
"-O|-|-O--|-||--O|OO|OOO|O|-|-|O-|"
Returns: 5
"|--O-|---O-||--|-|OO|-"
Returns: 3
"O-----|-|OO-|-||||O-|-O|---"
Returns: 4
"O----O|-|--|-|O|-O-|O||-|----|-OO--|--|--OO-|---O|"
Returns: 7
"||||O-"
Returns: 0
"--O|O"
Returns: 0
"|------|-||-"
Returns: 0
"--|O|O"
Returns: 1
"|O--O-"
Returns: 0
"|OO"
Returns: 0
"-||-|-O|OOO-|"
Returns: 2
"O-"
Returns: 0
"-O|O-O-|||-|--||--|O"
Returns: 4
"||"
Returns: 0
"---|-OO"
Returns: 0
"---||-O|O|--O"
Returns: 2
"||"
Returns: 0
"||O-|-OO|O|-|-|O--|---||-|O|-||"
Returns: 5
"|O"
Returns: 0
"||"
Returns: 0
"O||"
Returns: 0
"OO|||-|"
Returns: 0
"|-|-|-"
Returns: 0
"+==*=-*)*-O*+-((-+-=*-+"
Returns: 0
"+O(-|O=|"
Returns: 0
"||+O"
Returns: 0
"=||+OOO(*="
Returns: 0
")O)-"
Returns: 0
")||O"
Returns: 0
"||O"
Returns: 0
"*-=)+-)()--)"
Returns: 0
"(=*|O--))=+)"
Returns: 0
"|OO-)(==(|=|+|*+O(*-+-)++)+=)=O=(O-|O)(*=(*-*-(*-*"
Returns: 2
"O|--O-=+*=O-)=)(+|--||(-+--+(=O()=(O*(*(=)**O=|-|+"
Returns: 3
"-O(*"
Returns: 0
"-(("
Returns: 0
"-|*)O|"
Returns: 0
"O*="
Returns: 0
"-((+=+=)|OO)(|((--+|"
Returns: 1
"=(())-O|*O=*-=O*)-==*"
Returns: 0
"*)(="
Returns: 0
"O)=**-O"
Returns: 0
")((="
Returns: 0
"==)+"
Returns: 0
"|=|"
Returns: 0
"(-O"
Returns: 0
"*|O"
Returns: 0
"O*+)**O**=*))-=(-|O+(--*O(O|O(=-+|+*+=(O(="
Returns: 1
"-+)+*=)"
Returns: 0
")OO-"
Returns: 0
")((*|O|*((+)|)|OO|O**|O)*)(++)"
Returns: 0
"O*=="
Returns: 0
"|O=|)**(|-+**("
Returns: 0
"--O"
Returns: 0
"|-+-|"
Returns: 0
"OO||--"
Returns: 1
"---OOO***"
Returns: 0
"|-O-"
Returns: 0
"||||||--OOOO"
Returns: 1
"|*O*|"
Returns: 0
"-------------OOOOOOOOOOO||||||"
Returns: 3
"||--++"
Returns: 0
"||||||||||||||||||||||||||--------------O-|"
Returns: 1
"|||||-----O"
Returns: 1