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 47 48 49 50 51 52 53 54 55 56 57 58 |
#include <iostream> #include <cstdio> #include <sstream> #include <string> #include <cstring> using namespace std; char s[2000000+10]; int main() { int n,dist,prev_idx; char prev; bool first; while(scanf("%d",&n),n) { dist= n; first=0; scanf("%s",s); for(int i=0;i<n;i++) { //scanf("%c",&s[i]); if(s[i]=='Z') dist=0; if(s[i]=='R' && first==false) { prev='R'; prev_idx=i; first=true; continue; } if(s[i]=='D' && first==false) { prev='D'; prev_idx=i; first=true; continue; } if(first==1 && (s[i]=='D' || s[i]=='R')) { if(prev==s[i]) { prev_idx=i; } else { if(dist>(i-prev_idx)) dist=i-prev_idx; prev=s[i]; prev_idx=i; } } }//for ends printf("%d\n",dist); } return 0; } |