Sujet : Re: Suggested method for returning a string from a C program?
De : nospam (at) *nospam* dfs.com (DFS)
Groupes : comp.lang.cDate : 19. Mar 2025, 18:23:47
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vreuj1$1asii$4@dont-email.me>
References : 1 2 3 4
User-Agent : Betterbird (Windows)
On 3/19/2025 5:55 AM, Michael S wrote:
On Wed, 19 Mar 2025 00:38:44 -0400
DFS <nospam@dfs.com> wrote:
On 3/18/2025 11:07 PM, Tim Rentsch wrote:
>
>
Have you thought about how large the value of 'n' can
become inside the while() loop?
>
I was too smug in my first reply. After Keith pointed out I needed
to read from stdin, I submitted the code again and it passed some
tests but failed with 'OUTPUT LIMIT EXCEEDED' when n = 159487.
>
Updating int to long worked, and now I'm bona fide!
>
So thanks.
What you did happens to be sufficient for a particular environment
(supposedly, x86-64 Linux) used both by yourself and by the server that
tests results.
In more general case, 'long' is not guaranteed to handle numbers in
range up to 18,997,161,173 that can happen in this test.
How did you determine that?
I ran the program for inputs 1 to 10^6 (1 million):
Windows11, Tiny C compiler
$ ptime weird 1 1000000
max n = 56991483520 reached at input = 704511
Execution time: 0.559 s
Kali Linux (Windows WSL), gcc
$ time ./weird 1 1000000
max n = 56991483520 reached at input = 704511
real 0m0.330s
(56,991,483,520)
Something like int64_t would be safer.
Indeed. My code bombed using long when the input n = 151177.
Used int64_t and it didn't bomb.
Thanks
| Date | Sujet | # | | Auteur |
| 22 Apr 26 | … | | | |
Haut de la page
Les messages affichés proviennent d'usenet.
NewsPortal