c++运行时错误?如何解决这个问题并检查?
#include<iostream>
using namespace std;
int main()
{
int hash, opp, i, j, c = 0;
//cout<<"enter hasmat army number and opponent number\n";
while(cin>>hash>>opp)
{
cout<<opp-hash<<endl;
}
}
本题时限:3.000 秒 我如何验证和测试这个条件?
我正在将其在线提交到计算机,我如何准确地知道运行时错误?我应该计算运行时间和内存吗?
解释一下如何在 linux 中检查 c++ 的运行时和内存,我使用的是 gcc 版本 4.4.1 (Ubuntu 4.4.1-4ubuntu9)。
#include<iostream>
using namespace std;
int main()
{
int hash, opp, i, j, c = 0;
//cout<<"enter hasmat army number and opponent number\n";
while(cin>>hash>>opp)
{
cout<<opp-hash<<endl;
}
}
time limit for this problem: 3.000 seconds
how can i verify and test this condition?
i'm submitting this to a computer online, how exactly can i know run time error? should i calculate run time and memory?
explain me how to check runtime and memory in c++ in linux, i'm using gcc version 4.4.1 (Ubuntu 4.4.1-4ubuntu9).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编译完程序后,通过使用 Unix 程序
time
运行它来检查其运行时间:这将打印花费了多少“真实”(人类)时间,以及多少 CPU(活动处理) ) 时间。
如果您想检查程序使用了多少内存,请在调试器中运行它并在要检查内存使用情况的位置设置一个断点,或者只是在代码中放置一个很长的
sleep()
并运行无需调试器即可实现。然后,您可以使用ps
或top
等工具来查看程序使用了多少内存(虚拟内存、驻留内存等)。Once you've compiled your program, check its running time by running it with the Unix program
time
:This will print how much "real" (human) time was taken, and how much CPU (active processing) time.
If you want to check how much memory your program uses, run it in the debugger and set a breakpoint where you want to inspect the memory usage, or just put a long
sleep()
in your code and run it without the debugger. Then you can use tools likeps
ortop
to see how much memory (virtual, resident, etc.) is in use by your program.