Advertisement
add1ctus

COW

Feb 23rd, 2015
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. Bessie the cow has stumbled across an intriguing inscription carved into a large stone in the middle of her favorite grazing field. The text of the inscription appears to be from a cryptic ancient language involving an alphabet with only the three characters C, O, and W. Although Bessie cannot decipher the text, she does appreciate the fact that C, O, and W in sequence forms her favorite word, and she wonders how many times COW appears in the text.
  2.  
  3. Bessie doesn't mind if there are other characters interspersed within COW, only that the characters appear in the correct order. She also doesn't mind if different occurrences of COW share some letters. For instance, COW appears once in CWOW, twice in CCOW, and eight times in CCOOWW.
  4.  
  5. Given the text of the inscription, please help Bessie count how many times COW appears.
  6.  
  7. INPUT FORMAT:
  8.  
  9. The first line of input consists of a single integer N <= 10^5. The second line contains of a string of N characters, where each character is either a C, O, or W.
  10.  
  11. OUTPUT FORMAT:
  12.  
  13. Output the number of times COW appears as a subsequence, not necessarily contiguous, of the input string.
  14.  
  15. Note that the answer can be very large, so make sure to use 64 bit integers ("long long" in C++, "long" in Java) to do your calculations.
  16.  
  17. SAMPLE INPUT:
  18.  
  19. 6
  20. COOWWW
  21. SAMPLE OUTPUT:
  22.  
  23. 6
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement