Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cctype>
- #include <iostream>
- #include <cstdio>
- #include <string>
- #include <cstring>
- using namespace std;
- int main(int argc, char** argv) {
- int n,longit,ext,dist,min;
- bool primera,foundR,foundD;
- string cad;
- while(scanf("%d",&n)){
- min=20000001;
- primera=true;
- foundR=false;foundD=false;
- if(n==0) break;
- getchar();
- getline(cin,cad);
- longit=cad.size();
- for(int i=0;i<longit;i++){
- if (cad[i]=='Z'){
- min=0;
- break;
- }
- if(cad[i]=='R' && primera){
- ext=i;
- foundR=true;
- primera=false;
- }
- if(cad[i]=='D'&& primera){
- ext=i;
- foundD=true;
- primera=false;
- }
- /*ya he encontrado un R, entonces tomo mi nuevo extremo*/
- if (cad[i]=='R'&& !primera && foundR && !foundD){
- ext=i;
- }else if(cad[i]=='D' && !primera && foundD &&!foundR){
- /*encontre un D pero encontre otro mas cercano*/
- ext=i;
- }else if(cad[i]=='D' && !primera && !foundD && foundR){
- /*encontre un D y justo habia encontrado ya un R*/
- dist=i-ext;
- if(dist<=min){
- min=dist;
- }
- foundR=false; /*comienzo buscando desde D*/
- foundD=true;
- ext=i;
- }else if(cad[i]=='R' && !primera && !foundR && foundD){
- /*encontre un D y justo habia encontrado ya un R*/
- dist=i-ext;
- if(dist<min){
- min=dist;
- }
- foundD=false; /*comienzo buscando desde R*/
- foundR=true;
- ext=i;
- }
- }
- printf("%d\n",min);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement