1秒可以打印多少个数字
How many numbers that you can print in 1 second
我想打印n个数字到stdout
,最大时间限制为1秒,n最大为100000。
我尝试将输出连接为字符串,然后将其流式传输到 cout
,但没有成功。
我的代码:
#include <iostream>
using namespace std;
int main() {
int n = 100000;
for(int i=1;i<=n;i++)
cout<<i<<" ";
return 0;
}
它打印到 12769,然后给出运行时错误:
根据您的屏幕截图,在我看来您正在使用 ideone.com
编译和 运行 您的代码。根据 FAQ:
What is the size limit for the source code, input and output?
64 kB.
当输出达到数字 12774 的第 5 位时,您的输出超出了大小限制。请尝试编译并 运行在您的本地计算机上编译它。
附带说明一下,您在问题中说过代码的最大 运行ning 时间为 1 秒,但您没有在代码中实现这一点。因此,即使您修复了 运行 时间错误,您也不会得到预期的结果。
我想打印n个数字到stdout
,最大时间限制为1秒,n最大为100000。
我尝试将输出连接为字符串,然后将其流式传输到 cout
,但没有成功。
我的代码:
#include <iostream>
using namespace std;
int main() {
int n = 100000;
for(int i=1;i<=n;i++)
cout<<i<<" ";
return 0;
}
它打印到 12769,然后给出运行时错误:
根据您的屏幕截图,在我看来您正在使用 ideone.com
编译和 运行 您的代码。根据 FAQ:
What is the size limit for the source code, input and output? 64 kB.
当输出达到数字 12774 的第 5 位时,您的输出超出了大小限制。请尝试编译并 运行在您的本地计算机上编译它。
附带说明一下,您在问题中说过代码的最大 运行ning 时间为 1 秒,但您没有在代码中实现这一点。因此,即使您修复了 运行 时间错误,您也不会得到预期的结果。