maybe a floating point issue?
Dennis
dkorpel at gmail.com
Fri Sep 19 10:25:37 UTC 2025
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;
}
```
More information about the Digitalmars-d
mailing list