gpt4 book ai didi

ruby - 我数不清文件中使用了多少次相同的字符

转载 作者:行者123 更新时间:2023-12-05 00:48:41 25 4
gpt4 key购买 nike

<分区>

我有一些文本要检查相同的字符。当我检查时:放 file.count("AB")。结果:399 但应该是 3

alphabet = ["A","B","C","D","E","F","G","H","I","J",
"K","L","M","N","O","P","Q","R","S","T",
"U","V","W","X","Y","Z"," ",".",",",";",
"-","'"
]

file = File.read("vt_00.txt")
i = 0


while i < alphabet.count do
single_char_count = file.count(alphabet[i])
puts "#{alphabet[i]} = #{single_char_count}"
j = 0
while j < alphabet.count do
two_chars = alphabet[i] + alphabet[j]
two_chars_count = file.count(two_chars)
puts "#{two_chars} = #{two_chars_count}"
j += 1
end
i += 1
end

当我检查时:放 file.count("AB")。结果:399 但应该是 3

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com