Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <algorithm>
- #include <vector>
- using namespace std;
- int main ()
- {
- vector <int > distance ;
- int highway , x , num;
- string s;
- bool foun_Z=false;
- while(cin>>highway)
- {
- if(highway==0)
- {
- break;
- }
- cin>>s;
- for(int i=0 ; i< s.size() ; i++)
- {
- if(s[i]=='Z')
- {
- foun_Z=true;
- cout<<0<<endl;
- break;
- }
- else if(s[i]=='R')
- {
- num=s.find('D',i);
- if(num>=0)
- {
- distance.push_back(num-i);
- }
- num=s.rfind('D',i);
- if(num>=0)
- {
- distance.push_back(i-num);
- }
- }
- }
- if(foun_Z==false)
- {
- sort(distance.begin() ,distance.end());
- cout<<distance.front()<<endl;
- }
- distance.clear();
- foun_Z=false;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment