擅长:python、mysql、java
<p>最简单的方法是首先生成所有可能的三元组:</p>
<pre><code>lines = ["`1234567890-=", "qwertyuiop[]", "asdfghjkl;'\\", "<zxcvbnm,./"]
triples = []
for line in lines:
for i in range(len(line)-2):
triples.append(line[i:i+3])
</code></pre>
<p>如果只需要字符而不需要数字和括号等,请用上面的<code>lines</code>替换</p>
<pre><code>lines = ["qwertyuiop", "asdfghjkl", "zxcvbnm"]
</code></pre>
<p>现在我们有了所有的三元组,您可以使用<code>count</code>检查三元组在输入字符串中出现的次数。</p>
<pre><code>input_string = input().strip().lower()
score = 0
for triple in triples:
number_of_occurrences = input_string.count(triple)
score += 5 * number_of_occurrences
print(score)
</code></pre>
<p>砰,给你。它的作用是计算每个三元组在一个字符串中出现的次数,这样你就知道要加5个点需要多少次。我们使用<code>str.lower()</code>将所有字符转换为小写,因为正如您所说,大写并不重要。</p>
<p>如果字符串包含某个三元组一次还是三次是相同的,则可以执行以下操作:</p>
<pre><code>input_string = input().strip().lower()
score = 0
for triple in triples:
if triple in input_string:
score += 5
print(score)
</code></pre>