简体   繁体   English

代码卡纸练习python

[英]Code jam exercise python

I found out about Code Jam and decided to take a try on practice exercises. 我了解了Code Jam,并决定尝试练习。 So I started with year 2008 qualification round problem A: Saving the Universe . 因此,我从2008年资格回合问题A: 拯救宇宙入手。

I found a solution for this problem from the achieves of Code Jam. 我从Code Jam的成就中找到了解决此问题的方法。

#!/usr/bin/python2.5

for case in range(input()):
    engines = set()
    for i in range(input()):
        engines.add(raw_input())
    s = 0
    t = engines.copy()
    for k in range(input()):
        q = raw_input()
        t.discard(q)
        if not len(t):
            s = s + 1
            t = engines.copy()
            t.discard(q)

    print "Case #%s: %s" % ((case + 1), s)

First of all I tried to pass the input from small file that is available for download. 首先,我尝试从可下载的小文件传递输入。 I opened the .in file with Wordpad, I copied everything and then ran the program and pasted the input to the shell. 我用写字板打开.in文件,我复制了所有内容,然后运行程序并将输入粘贴到外壳中。 I got this error: 我收到此错误:

File "<string>", line 3
    for case in range(input()):
      ^
SyntaxError: invalid syntax

Am I doing something wrong? 难道我做错了什么?

You need to type in shell: 您需要输入shell:

$ python yourfile.py <A-small-practice.in

This way each line of file will be correctly read by your program ('<' passes the file to the program as input) 这样,您的程序将正确读取文件的每一行(“ <”将文件作为输入传递给程序)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM