2315.php 617 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. class Solution {
  3. /**
  4. * @param String $s
  5. * @return Integer
  6. */
  7. function countAsterisks($s) {
  8. $in = false;
  9. $count = 0;
  10. foreach ( str_split($s) as $c ) {
  11. if ( $c == '|' ) { $in = !$in; }
  12. if ( $in == false && $c == '*' ) { ++$count; }
  13. }
  14. return $count;
  15. }
  16. }
  17. function main() {
  18. function r($s) {
  19. $S = new Solution;
  20. $t = $S->countAsterisks($s);
  21. echo "Solution().countAsterisks(\"$s\") = $t\n";
  22. }
  23. r("l|*e*et|c**o|*de|");
  24. r("iamprogrammer");
  25. r("yo|uar|e**|b|e***au|tifu|l");
  26. }
  27. main();