Skip to content

Instantly share code, notes, and snippets.

@felinebabies
Created December 20, 2017 12:28
Show Gist options
  • Save felinebabies/597e277e858539c9424557df779147dd to your computer and use it in GitHub Desktop.
Save felinebabies/597e277e858539c9424557df779147dd to your computer and use it in GitHub Desktop.
古いチャットログを解析
input_lines = $stdin.read.split("\n")
linecount = input_lines[0].to_i
chatlines = input_lines[1..-1]
chatarr = chatlines.map do |item|
item.split(" ")
end
grouparr = chatarr.group_by do |item|
item[0]
end
resultarr = []
grouparr.each do |item|
chatid = item[0]
chatstr = item[1].inject("") do |memo, str|
memo + str[1]
end
resultstr = "#{chatid.to_s} #{chatstr}"
resultarr << [chatid.to_i, resultstr]
end
resultarr.sort! do |a,b|
a[0] <=> b[0]
end
resultarr.each do |item|
puts item[1]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment