【问题标题】:I Have passed all the test cases for the problem and even all the test cases on Udebugg and still getting a WA verdict on UVA online judge我已经通过了该问题的所有测试用例,甚至通过了 Udebugg 上的所有测试用例,并且仍然获得了关于 UVA 在线法官的 WA 判决
【发布时间】:2019-06-20 12:27:45
【问题描述】:

评委姓名-UVA在线评委
问题名称-汉堡时间?
问题 ID-11661
链接-https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2708

我已经尝试解决它并通过了问题 pdf 以及 uDebug 中提供的所有测试用例。当我提交解决方案时,我得到一个错误的答案裁决。请帮助我解决我哪里出错了。提前致谢。

#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;
}

【问题讨论】:

  • 要么 1) 调试你的代码,要么 2) 向“法官”投诉。
  • 3) 描述您的问题here
  • 为什么要一次读取一个字符?一次读取整个字符串,并调用函数以使用该字符串作为参数来获取最小距离。以这种方式做事不会那么混乱,并且会适当地集中你的问题。这说明这些在线评委网站没有教如何正确编写代码。
  • As an example。这是您在此处发布问题时应该努力发布和询问的内容。我们不需要知道“法官”,关心t 或任何那些输入例程等。您需要做的就是找到测试用例,将其放入该字符串,然后调试您的代码。跨度>

标签: c++ c++11 adhoc


【解决方案1】:

对于

3

Z..

此代码失败。在取第一个字符之后,将 ch=='Z' ans=0 的条件放在开头。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-24
    • 1970-01-01
    • 2015-01-14
    • 1970-01-01
    • 1970-01-01
    • 2021-12-26
    • 2020-06-01
    • 1970-01-01
    相关资源
    最近更新 更多