| 12345678910111213141516171819202122232425262728293031 |
- <?php
- class Solution {
- /**
- * @param String $s
- * @return Integer
- */
- function countAsterisks($s) {
- $in = false;
- $count = 0;
- foreach ( str_split($s) as $c ) {
- if ( $c == '|' ) { $in = !$in; }
- if ( $in == false && $c == '*' ) { ++$count; }
- }
- return $count;
- }
- }
- function main() {
- function r($s) {
- $S = new Solution;
- $t = $S->countAsterisks($s);
- echo "Solution().countAsterisks(\"$s\") = $t\n";
- }
- r("l|*e*et|c**o|*de|");
- r("iamprogrammer");
- r("yo|uar|e**|b|e***au|tifu|l");
- }
- main();
|