-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB.cpp
More file actions
46 lines (44 loc) · 694 Bytes
/
Copy pathB.cpp
File metadata and controls
46 lines (44 loc) · 694 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include<iostream>
using namespace std;
int main()
{
string s;
cin>>s;
int n=s.length();
int a[n-1],b[n-1];
for(int i=0;i<n-1;i++)
{
if(s[i]==s[i+1])
{
a[i]=1;
}
else
{
a[i]=0;
}
//cout<<a[i]<<' ';
}
int sum=0,m,l,r;
//b[0]=a[0];
for(int i=0;i<n-1;i++)
{
sum+=a[i];
b[i]=sum;
//cout<<b[i]<<' ';
}
cin>>m;
for(int i=0;i<m;i++)
{
cin>>r>>l;
if(r==1)
{
sum=b[l-2];
}
else
{
sum=b[l-2]-b[r-2];
}
cout<<sum<<endl;
}
return 0;
}