Created
January 22, 2017 00:47
-
-
Save KhaledElshamy/2aaa0845a7ca4020ef46a19d3778025d to your computer and use it in GitHub Desktop.
B. Ilya and Queries-codeforces
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <bits/stdc++.h> | |
| using namespace std; | |
| int main() { | |
| //Dynamic programming | |
| int num, x,y,d[100000]={0}; | |
| vector<int>m; | |
| string s; | |
| cin>>s>>num; | |
| for(int i=s.size()-2;i>=0;i--) | |
| { | |
| if(s[i]==s[i+1]) | |
| d[i]=d[i+1]+1; | |
| else | |
| d[i]=d[i+1]+0; | |
| } | |
| while(num--) | |
| { | |
| cin>>x>>y; | |
| m.push_back(d[x-1]-d[y-1]); | |
| } | |
| for(int i=0;i<m.size();i++) | |
| cout<<m[i]<<endl; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment