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

Автор rgkbitw, история, 9 лет назад, По-английски

I came across this problem in UVa OJ. 272-Text Quotes

Well, the problem is quite trivial. But the thing is I am not able to read the input. The input is provided in the form of text lines and end of input is indicated by EOF.

In C/C++ this can be done by running a while loop:

  while( scanf("%s",&s)!=EOF ) { //do something } 

How can this be done in python .?
I have searched the web but I did not find any satisfactory answer.

Please Help Me!
  • Проголосовать: нравится
  • +5
  • Проголосовать: не нравится

»
9 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

in python 3:

while True:
    try:
        s=input()
        #do something
    except EOFERROR:
        break
»
9 лет назад, скрыть # |
 
Проголосовать: нравится +8 Проголосовать: не нравится

Just iterate over the input.

for line in sys.stdin:
    process_line(line)
»
9 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

That's why you don't do UVa (if possible) :P.