-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUva11661.cpp
More file actions
63 lines (54 loc) · 1.26 KB
/
Copy pathUva11661.cpp
File metadata and controls
63 lines (54 loc) · 1.26 KB
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
59
60
61
62
63
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <algorithm>
#include <map>
#include <sstream>
using namespace std;
int main()
{
int L;
while(cin>>L){
if(L==0)break;
string S;
cin>>S;
bool Dfound=false;bool Rfound=false;
int dist;
int bestSoFar=L;
int i=0;
int lastR=-L;
int lastD=-L;
for(string::iterator it=S.begin();it!=S.end();it++,i++){
int min=0;
if(*it=='Z'){
bestSoFar=0;
break;
}
if(*it=='D'){
lastD=i;
Dfound=true;
if(Rfound){
if(lastD>lastR)min=lastD-lastR;
else min=lastR-lastD;
if(min<bestSoFar)bestSoFar=min;
}
}
else if(*it=='R'){
lastR=i;
Rfound=true;
if(Dfound){
if(lastD>lastR)min=lastD-lastR;
else min=lastR-lastD;
if(min<bestSoFar)bestSoFar=min;
}
}
}
cout<<bestSoFar<<endl;
}
return 0;
}