笑脸组成规则:
-笑脸必须包含眼睛。用“:”或“;”表示。
-笑脸可以有鼻子,也可以没有。用“-”或“~”表示。
-笑脸必须有嘴巴。用“)”或“D”表示。
例如笑脸:
:) ;) :~) ;~) :-) ;-) :D ;D等
Given an array (arr) as an argument complete the function countSmileys that should return the total number of smiling faces.
Rules for a smiling face:
-Each smiley face must contain a valid pair of eyes. Eyes can be marked as : or ;
-A smiley face can have a nose but it does not have to. Valid characters for a nose are - or ~
-Every smiling face must have a smiling mouth that should be marked with either ) or D.
No additional characters are allowed except for those mentioned.
Valid smiley face examples:
:) ;) :~) ;~) :-) ;-) :D ;D :-D ;-D :~D ;~D
Invalid smiley faces:
;( :> :} :]
代码:
import java.util.ArrayList;
import java.util.Arrays;
impor