immuntasir

Untitled

Nov 13th, 2015
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. #include <cstdio>
  2. #include <cstring>
  3. typedef struct data {
  4. int l, r;
  5. } dat;
  6.  
  7. int main() {
  8. int n, i;
  9. scanf("%d", &n);
  10. while (n--) {
  11. char str[10010];
  12. scanf("%s", str);
  13. int len = strlen(str);
  14. dat ara[len];
  15. int ocount = 0;
  16. int lcount = 0;
  17. for (i=0; i<len; i++) {
  18. if (str[i] == 'L') lcount++;
  19. else if (lcount!=0) ara[ocount++].l = lcount;
  20. }
  21. long long int ans = 0;
  22. for (i=0; i<ocount; i++) {
  23. ans += (ara[i].l*(lcount-ara[i].l));
  24. }
  25. printf("%I64d\n", ans);
  26. }
  27. return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment