擅长:python、mysql、java
<p>如果将整个输入作为一个字符串读取,则可以尝试使用<code>stdin.readline()</code>而不是<code>raw_input</code>来捕获输入流:</p>
<pre><code>from sys import stdin
T = int(stdin.readline())
</code></pre>
<p>然而,由于这是一个编码竞争,我认为速度是关键。由于IO操作在计算上很昂贵,您应该欢迎有机会一次读取所有输入。换言之,一次读入并解析代码中的输入通常更快。我想在你的情况下,它会看起来像这样(假设它是按设计同时出现的):</p>
<pre><code>data = raw_input().splitlines()
#(or data = sys.stdin.read().splitlines() or data = list(sys.stdin.readlines()))
T = int(data[0])
S = (s.split() for s in data[1:])
</code></pre>