如何c++ assert() 可以创建无限循环吗?
机器人评委太烂了!仅在删除以下代码块后,我才被 UVA 接受:
cin >> ntc;
/* extract newline from previous read */
char dummy(0);
cin.get(dummy);
assert( '\n'==dummy );
/* newline extract completes */
将其替换为:
cin >> ntc;
getline( cin, inputN ); /* extract remaining '\n' */
在替换尊敬的之前UVA 的机器人法官会做出以下裁决:
您的提交....已失败,判决超出时间限制。
您的程序使用的 CPU 时间超出了此问题所允许的时间。这意味着您的算法不够快或者进入了无限循环。
替换后程序运行时间为 0.052 秒!
- 它以什么方式与替换代码相关?
- 有没有关于UVA机器人判断与其他编译器有何不同的文档?这样我就知道在线判断有哪些功能/方法可用。
我用的是MinGW。
Robot judges suck! I've been accepted by UVA, only after removing the following chunks of code:
cin >> ntc;
/* extract newline from previous read */
char dummy(0);
cin.get(dummy);
assert( '\n'==dummy );
/* newline extract completes */
Replacing it with :
cin >> ntc;
getline( cin, inputN ); /* extract remaining '\n' */
Before replacement the honorable robot judge at UVA would verdict:
Your submission .... has failed with verdict Time limit exceeded.
Your program used more CPU time than what is allowed for this problem. That means that your algorithm is not fast enough or that it entered into an infinite loop.
After the replacement the program took 0.052 seconds to run!
- In what way could it be related with the replaced code?
- Is there any document on how does UVA robot judge differ from other compilers? So that I know what functions/methods are available on the online judge.
I use MinGW.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
断言不能创建无限循环。
我的猜测是,当断言触发时,操作系统会显示即时调试提示(“程序中发生错误... [调试] [取消]”)。 (抱歉,我现在没有运行Windows,所以无法检查实际的措辞)。由于没有人按下任何一个按钮,并且直到有人按下该按钮后该进程才会终止,因此机器人认为该程序仍在运行。
我认为这是 UVA 设置中的错误。必须禁用即时调试。
Assert can't create an infinite loop.
My guess is that when assert triggered, a just-in-time debugging prompt was displayed by the OS ("An error has occurred in the program... [Debug] [Cancel]"). (Sorry, I'm not running Windows at the moment, so can't check the actual wording). Since noone was there to press either button and the process is not terminated until someone does, the robot thought the program was still running.
I think it's an error in the UVA setup. Just-in-time debugging has to be disabled.