-2

Judge Name- UVA Online Judge
Problem Name-Burger Time?
Problem ID-11661
Link-https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2708

I Already Tried To solve It and passed all the test cases provided in the problem pdf as well as on uDebug.Still when i submit the solution, i get a Wrong Answer Verdict.Please Help me with where i am going wrong.Thanks In Advance.

#include <iostream>
using namespace std;
int main() {
    long n;
    while(1) {
        cin >> n;
        if(n == 0) exit(0);
        char ch;
        long countr = 0;
        cin >> ch;
        char start = ch;
        long ans = 1000000000;
        for(long i = 1; i < n; i++) {
            cin >> ch;
            countr++;
            if(ch == 'Z') {
                ans = 0;
            } else if(start == 'R' && ch == 'D') {
                if(countr < ans) {
                    ans = countr;
                }
            } else if(start == 'D' && ch == 'R') {
                if(countr < ans) {
                    ans = countr;
                }
            }
            if(ch == 'R') {
                start = ch;
                countr = 0;
            }
            if(ch == 'D') {
                start = ch;
                countr = 0;
            }
        }
        cout << ans << endl;
    }
    cout << endl;
    return 0;
}
Ted Lyngmo
  • 93,841
  • 5
  • 60
  • 108
  • 2
    Either 1) Debug your code, or 2) Complain to the "judge". – PaulMcKenzie Jun 20 '19 at 12:31
  • 3) Describe your problem [here](https://stackoverflow.com/posts/56686001/edit). – Ted Lyngmo Jun 20 '19 at 12:36
  • 1
    Why read a character at a time? Read the entire string at once, and call the function to get the minimum distance using that string as an argument. Doing things that way would be less cluttered, and would focus *your* question appropriately. This goes to show that these online judge websites do not teach how to write code properly. – PaulMcKenzie Jun 20 '19 at 12:51
  • 2
    [As an example](http://coliru.stacked-crooked.com/a/cfa48966ef193917). This is what you should strive to post and ask on when posting questions here. We do not need to know about a "judge", care about `t` or any of those input routines, etc. All you need to do is find the test case, put it into that string, and debug your code. – PaulMcKenzie Jun 20 '19 at 12:57

1 Answers1

0

For

3

Z..

this code fails. Put condition for ch=='Z' ans=0 in the beginning,after you are taking the first character.

DSV
  • 5
  • 5