Created
June 17, 2017 22:42
-
-
Save takahashilabo/4fa47d98dd6d123b1fdcfd538122e4d8 to your computer and use it in GitHub Desktop.
This code counts consecutive lines in standard input
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| data = [] | |
| while s = gets | |
| data << s.chomp | |
| end | |
| tmp = {} | |
| data.each do |item| | |
| if tmp.has_key?(item) then | |
| tmp[item] << item | |
| else | |
| tmp[item] = [item] | |
| end | |
| end | |
| tmp.each_key do |key| | |
| print key, ",", tmp[key].size, "\n" | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment