【发布时间】: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或任何那些输入例程等。您需要做的就是找到测试用例,将其放入该字符串,然后调试您的代码。跨度>