The aim of this task is to identify, clean up, and mark out all the faces in any given 'image'.
What's in a face?
A face will be a ZxZ square where Z is an odd integer greater than 1. The top left and right corners and the centre will be 'O' characters, and the bottom line will be a '\' and a '/' surrounding enough '_' characters to fill the rest of the line. Examples:
a 3x3 face:
O O
O
\_/
a 5x5 face:
O O
O
\___/
a 7x7 face:
O O
O
\_____/
etc.
Input
Input will be on STDIN and will consist of a number of equal length strings of characters.
Output
Output should be the input with all recognizable faces cleared (i.e. all characters except the eyes, nose and mouth shoud be removed from within the face's bounds) and boxed (surrounded by +, -, and | characters). Where two or more faces overlap both should be cleared and boxed but priority should be given to the larger face (it should be placed on top); if both faces are the same size, the priority is left to the discretion of the implementer. If the input has no faces, output should be the same as input.
Some examples
Input:
*******
*******
**O*O**
***O***
**\_/**
*******
*******
Output:
*******
*+---+*
*|O O|*
*| O |*
*|\_/|*
*+---+*
*******
Input (incomplete face):
*******
*******
**O*O**
*******
**\_/**
*******
*******
Output:
*******
*******
**O*O**
*******
**\_/**
*******
*******
Input (nested faces):
*******
*O***O*
**O*O**
***O***
**\_/**
*\___/*
*******
Output:
+-----+
|O O|
| |
| O |
| |
|\___/|
+-----+
Input (multiple faces):
~{$FJ*TBNFU*YBVEXGY%
FOCO$&N|>ZX}X_PZ<>}+
X$OOPN ^%£)LBU{JJKY%
@\_/$£!SXJ*)KM>>?VKH
SDY%£ILO(+{O:HO(UR$W
XVBFTER^&INLNLO*(&P:
>?LKPO)UJO$£^&L:}~{&
~@?}{)JKOINLM@~}P>OU
:@<L::@\___/GER%^*BI
@{PO{_):<>KNUYT*&G&^
Output:
+---+*TBNFU*YBVEXGY%
|O O|&N|>ZX}X_PZ<>}+
| O |N ^%£)LBU{JJKY%
|\_/|£+-----+M>>?VKH
+---+I|O O|HO(UR$W
XVBFTE| |LO*(&P:
>?LKPO| O |&L:}~{&
~@?}{)| |@~}P>OU
:@<L::|\___/|ER%^*BI
@{PO{_+-----+YT*&G&^
Input (near boundary):
~{$FJ*TBNFU*YBVEXGY%
OCO$&N|>ZX}X_PZ<>}+^
$OOPN ^%£)LBU{JJKY%{
\_/$£!SXJ*)KM>>?VKHU
SDY%£ILO(+{8:HO(UR$W
XVBFTER^&INLNLO*(&P:
>?LKPO)UJ^$£^&L:}~{&
~@?}{)JKOINLM@~}P>OU
:@<L::@BJYT*GER%^*BI
@{PO{_):<>KNUYT*&G&^
Output:
---+J*TBNFU*YBVEXGY%
O O|&N|>ZX}X_PZ<>}+^
O |N ^%£)LBU{JJKY%{
\_/|£!SXJ*)KM>>?VKHU
---+£ILO(+{8:HO(UR$W
XVBFTER^&INLNLO*(&P:
>?LKPO)UJ^$£^&L:}~{&
~@?}{)JKOINLM@~}P>OU
:@<L::@BJYT*GER%^*BI
@{PO{_):<>KNUYT*&G&^
Input (overlapping faces):
~{$FJ*TBNFU*YBVEXGY%
FXC£$&N|>ZX}X_PZ<>}+
X$*OPN O%£)LBO{JJKY%
@:U%$£!SXJ*)KM>>?VKH
SDY%£OLO(+{P:HO(UR$W
XVBFTER^&IOLNLO*(&P:
>?L\___/JR$£^&L:}~{&
~@?}{)JKOINLM@~}P>OU
:@<L::@\_____/R%^*BI
@{PO{_):<>KNUYT*&G&^
Output:
~{$FJ*TBNFU*YBVEXGY%
FX+---+-------+Z<>}+
X$|O |O O|JJKY%
@:| | |>?VKH
SD| O| |(UR$W
XV| | O |*(&P:
>?|\__| |:}~{&
~@+---| |}P>OU
:@<L::|\_____/|%^*BI
@{PO{_+-------+*&G&^