1 / 4
Jul 2011

Hi all,

This is supposed to be a very easy problem. But I just kept getting WA. Originally I thought it might be the precision issue. But after I changed to decimal, I still got WA. Would you please check what is wrong with my code?

Removed

Thanks in advance!

  • created

    Jul '11
  • last reply

    Jun '12
  • 3

    replies

  • 156

    views

  • 3

    users

There are no precision issues using doubles (i.e. Python floats) according to that problem.
You should never rely on the assumption that the number of input lines correspond to the given N. smiley
If you consider this, you'll get AC (without decimal module).

Thanks a lot numerix!
I never thought this could be the problem of my code. smiley

10 months later

Hi,

I'm getting WA for this problem, too. Similar to chaconnewuI assumed that it might be an issue of (too much) accuracy in python, since the only differences to an C++ Code I tried on IDEONE ocurred when the input figures were quite large.

This is my code:

""" Problem SPOJ 2524: Conversions (GNY07B) Short vers."""
import sys
def init_conversions():
    conv = {
            'kg': [2.2046, 'lb'], 'lb': [0.4536, 'kg'],
            'l': [0.2642, 'g'], 'g': [3.7854, 'l']
           }
    return conv
def main():
    cases = sys.stdin.read().split('\n')
    conversions = init_conversions()
    results = []
    for i, line in enumerate(cases[1:]):
        if line :
            number, unit = line.split()
            result = '%s %.4f %s' % (i + 1,
                                     float(number) * (conversions[unit][0]),
                                     conversions[unit][1])
            results.append(result)
    sys.stdout.writelines ('\n'.join(results))
    sys.stdout.write('\n')
if __name__ == '__main__':
    main()

Anyone seeing the mistake?
Regards
Daft