1 / 4
Nov 2012

Hello, I am a newbie in interacting with online judge system. could anyone can help me to write a sample code for a simple programme to read 2 numbers, and write it down in accepted format of online judge system.
Thanks so much.

  • created

    Nov '12
  • last reply

    Nov '12
  • 3

    replies

  • 240

    views

  • 2

    users

  • 1

    link

Hi and welcom here.
I' not sure if I undestand your question correctly. Usually input and output definitions are given in the problem description. And you can use "normal" Python methods to read and write in- / output (although these might not be the fastest). Did you read this?

A sample code snippet covering your question could be:
[bbone=Python3,506]number = input()
other = input()
print (number, other)[/bbone]

thank you for your help. In fact, I am trying to be familiar with new way of code. Normal, I use the code like:

file = open(filename) #to read a file or 
import sys
arg1 = sys.argv[1] .....

Well, there are dozens of code samples here in the forum which you can learn from. For problems with little input and output you can use input() and print () as shown in my posting above.

For problems with huge input it is not uncommon to use a pattern like this

[bbone=Python3,507]
import sys
for line in sys.stdin:
numbers = map(int, line.split())

do something with input numbers

result = sum (numbers)
sys.stdout.write('%d\n' % result)

[/bbone]

Suggested Topics

Want to read more? Browse other topics in Python or view latest topics.