fork download
  1. let deduct_10000_if_possible x = if (x >= 10000) then (x - 10000) else x;;
  2.  
  3. let rec numsubstrings str1 str2 l i j =
  4. if (j == (String.length str2)) then
  5. 1 else
  6. if (i == (String.length str1)) then
  7. 0 else
  8. if ((String.get str1 i) != (String.get str2 j)) then
  9. numsubstrings str1 str2 l (i+1) j
  10. else
  11. (deduct_10000_if_possible (numsubstrings str1 str2 (i::l) (i+1) (j+1)) + (numsubstrings str1 str2 l (i+1) j));;
  12.  
  13. let rec pad_string s =
  14. if ((String.length s) >= 4) then s
  15. else (pad_string ("0" ^ s));;
  16.  
  17. let pad_int i =
  18. pad_string (string_of_int i);;
  19.  
  20. let rec run_between i j =
  21. if (i > j) then 1
  22. else
  23. let s = (read_line ()) in
  24. let t = (print_endline ("Case #" ^ (string_of_int i) ^ ": " ^ (pad_int (numsubstrings s "welcome to code jam" [] 0 0)))) in
  25. run_between (i+1) j;;
  26.  
  27. let n = read_int ();;
  28. run_between 1 n
  29.  
Success #stdin #stdout 0.02s 2780KB
stdin
3
elcomew elcome to code jam
wweellccoommee to code qps jam
welcome to codejam
stdout
Case #1: 0001
Case #2: 0256
Case #3: 0000