Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. `Scanner console = new Scanner(System.in);
  2. String S = console.next();
  3. int n = console.nextInt();
  4. int sz = S.length();
  5. int[] dp = new int[sz];
  6. for(int i = 0; i < sz - 1; i++) {
  7. if(S.charAt(i) == S.charAt(i + 1)) dp[i + 1]++;
  8. dp[i + 1] += dp[i];
  9. }
  10. for(int i = 0; i < n; i++) {
  11. int l = console.nextInt(),
  12. r = console.nextInt();
  13. System.out.println(dp[r - 1] - dp[l - 1]);
  14. }`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement