Advertisement
juanjo12x

UVA_11661_Burger_Time

Jul 14th, 2014
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.90 KB | None | 0 0
  1. #include <cctype>
  2. #include <iostream>
  3. #include <cstdio>
  4. #include <string>
  5. #include <cstring>
  6.  
  7. using namespace std;
  8.  
  9. int main(int argc, char** argv) {
  10.     int n,longit,ext,dist,min;
  11.     bool primera,foundR,foundD;
  12.     string cad;
  13.     while(scanf("%d",&n)){
  14.         min=20000001;
  15.         primera=true;
  16.         foundR=false;foundD=false;
  17.       if(n==0) break;
  18.         getchar();
  19.       getline(cin,cad);
  20.       longit=cad.size();
  21.       for(int i=0;i<longit;i++){
  22.           if (cad[i]=='Z'){
  23.               min=0;
  24.               break;
  25.           }
  26.           if(cad[i]=='R' && primera){
  27.               ext=i;
  28.               foundR=true;
  29.               primera=false;
  30.           }
  31.           if(cad[i]=='D'&& primera){
  32.               ext=i;
  33.               foundD=true;
  34.               primera=false;
  35.           }
  36.           /*ya he encontrado un R, entonces tomo mi nuevo extremo*/
  37.           if (cad[i]=='R'&& !primera && foundR && !foundD){
  38.              ext=i;
  39.           }else if(cad[i]=='D' && !primera && foundD &&!foundR){
  40.              /*encontre un D pero encontre otro mas cercano*/
  41.               ext=i;
  42.           }else if(cad[i]=='D' && !primera && !foundD && foundR){
  43.               /*encontre un D y justo habia encontrado ya un R*/
  44.               dist=i-ext;
  45.               if(dist<=min){
  46.                   min=dist;
  47.                  
  48.               }
  49.                foundR=false; /*comienzo buscando desde D*/
  50.                foundD=true;
  51.                   ext=i;
  52.           }else if(cad[i]=='R' && !primera && !foundR && foundD){
  53.               /*encontre un D y justo habia encontrado ya un R*/
  54.               dist=i-ext;
  55.               if(dist<min){
  56.                   min=dist;
  57.                  
  58.               }
  59.               foundD=false; /*comienzo buscando desde R*/
  60.               foundR=true;
  61.               ext=i;
  62.           }
  63.       }
  64.       printf("%d\n",min);
  65.     }
  66.    
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement