简体   繁体   中英

How many numbers that you can print in 1 second

I want to print n numbers to stdout with a maximum time limit of 1 second and n can be up to 100000.

I tried to concatenate the output as a string and then stream this to cout but it did not work.

My code:

#include <iostream>
using namespace std;
 
int main() {
    int n = 100000;
    for(int i=1;i<=n;i++)
    cout<<i<<" ";
    return 0;
}

It prints until 12769 and then gives a runtime error:

1个

Based on your screenshot, it appears to me that you are using ideone.com to compile and run your code. Per the FAQ :

What is the size limit for the source code, input and output? 64 kB.

Your output exceeds the size limit when it reaches the 5th digit of the number 12774. Try compiling and running it on your local machine instead.

As a side note, you said in your question that the code is meant to have a maximum running time of 1 second, but you have not implemented this in the code. Therefore you will not get the result you expect even if you fix the runtime error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM