Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- `Scanner console = new Scanner(System.in);
- String S = console.next();
- int n = console.nextInt();
- int sz = S.length();
- int[] dp = new int[sz];
- for(int i = 0; i < sz - 1; i++) {
- if(S.charAt(i) == S.charAt(i + 1)) dp[i + 1]++;
- dp[i + 1] += dp[i];
- }
- for(int i = 0; i < n; i++) {
- int l = console.nextInt(),
- r = console.nextInt();
- System.out.println(dp[r - 1] - dp[l - 1]);
- }`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement