Блог пользователя NaimSS

Автор NaimSS, история, 17 месяцев назад, По-английски

Last week we had a local Contest available here (statements only in portuguese), and I was surprised when the easiest problem was getting a lot of Wrong Answers on test 1. All of them seemed correct, gave the correct output locally and were using GNU C11. For some reason, re-submitting the same code in GNU C++ gave AC. Why?

Problem Statement

Given the formula of gravitational attraction $$$F = \frac{G\cdot M_1 \cdot M_ 2}{d^2}$$$, find the value of $$$G$$$ given the mass of the 2 objects, the force and their positions on space (which is only a line).

The code

WA on 1

AC

After seeing this, I made an announcement for people to submit their problem using GNU C++ and a ton of AC came in... as a setter I was frustrated by such a bug and want to know why that happened :(

  • Проголосовать: нравится
  • +7
  • Проголосовать: не нравится

»
17 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by NaimSS (previous revision, new revision, compare).

»
17 месяцев назад, # |
  Проголосовать: нравится +15 Проголосовать: не нравится

As far as I see in custom invocation, the following code:

#include <stdio.h>

int main() {
    double x;
    scanf("%lf", &x);
    printf("%lf\n", x);
}

on the input 1.00 prints 0.000000. On the other hand, people had no troubles reading doubles in C not so long ago.

»
17 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Can't found any evidence that lf is correct specification, but standard clearly says that f must work fine (for printf, not scanf)