Advertisement
MiinaMagdy

11661 - Burger Time?

Sep 3rd, 2022
922
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. /*
  2.  *
  3.  * problem link: https://onlinejudge.org/index.php?option=onlinejudge&Itemid=8&page=show_problem&category=0&problem=2708&mosmsg=Submission+received+with+ID+27781275
  4.  *
  5.  * */
  6.  
  7. #include <bits/stdc++.h>
  8.  
  9. using namespace std;
  10.  
  11. #define ll long long
  12. #define endl '\n'
  13. #define sz(x) int(x.size())
  14. #define all(x) x.begin(), x.end()
  15.  
  16. int main() {
  17.     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  18.    
  19.     int n;
  20.     char s[2000005];
  21.     while (scanf("%d", &n), n) {
  22.         scanf("%s", s);
  23.         int l = -1, r = -1;
  24.         int ans = n;
  25.         for (int i = 0; i < n; i++) {
  26.             if (s[i] == 'Z') {
  27.                 ans = 0;
  28.             }
  29.             else {
  30.                 if (s[i] == 'R') l = i;
  31.                 else if (s[i] == 'D') r = i;
  32.                 if (~l && ~r) ans = min(ans, abs(l - r));
  33.             }
  34.         }
  35.         printf("%d\n", ans);
  36.     }
  37.    
  38. }
  39.  
Tags: UVA CP3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement