maybe a floating point issue?
czylabsonasa
nobody at dev.null
Fri Sep 19 10:51:43 UTC 2025
On Friday, 19 September 2025 at 10:25:37 UTC, Dennis wrote:
> On Friday, 19 September 2025 at 06:23:02 UTC, czylabsonasa
> wrote:
>> I'm trying to solve a programming contest
>> [problem](https://open.kattis.com/problems/anthony) in D. The
>> almost identical solution in C++ got accepted, but I'm unable
>> to find the issue in the D code...
>
> One difference between the C++ and D code is that your D code
> expects each line to end with a newline character:
>
> ```D
> for(i32 i=1;i<=A+C-1;i++){
> readf("%f\n",p[i]);
> }
> ```
>
> So if your input file is this:
>
> ```
> 1 1
> 0.500000
>
> ```
>
> Your C++ and D programs both output 0.500000. But if your input
> file lacks the final empty line:
>
> ```
> 1 1
> 0.500000
> ```
>
> The C++ version still works, but D throws an exception:
>
> ```
> std/format/spec.d(569): parseToFormatSpec: Cannot find
> character '
> ' in the input string.
> ```
>
> Perhaps change the D code to this:
>
> ```D
> for(i32 i=1;i<=A+C-1;i++){
> p[i] = readln().to!float;
> }
> ```
Denis, thanks for your time, but if there would such an input
file, then it would resulted in runtime error. Anyway, i tested
with readf(" %d %d",...)+read(" %f",...) and no change it is
wrong answer.
More information about the Digitalmars-d
mailing list