Created
June 17, 2017 04:39
-
-
Save takahashilabo/ec4084c9e82add45447c00b7fac51243 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
| cnt = 1 | |
| prev_s = "" | |
| while s = gets do | |
| s.chomp! | |
| if prev_s == "" then | |
| prev_s = s | |
| next | |
| end | |
| if s == prev_s then | |
| cnt += 1 | |
| else | |
| print prev_s, ",", cnt, "\n" | |
| prev_s = s | |
| cnt = 1 | |
| end | |
| end | |
| print prev_s, ",", cnt, "\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment