Created
January 20, 2016 13:12
-
-
Save dulltz/142db5d3ba20d075bb0c to your computer and use it in GitHub Desktop.
世界で戦うプログラミング力を鍛える150問 の解答
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
| # encoding: utf-8 | |
| counter = Hash.new(0) | |
| $stdin.read.split("").each do |w| | |
| counter[w] += 1 | |
| end | |
| if counter.values.max <= 1 | |
| puts "No duplication" | |
| elsif | |
| puts "duplication" | |
| end |
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
| # encoding: utf-8 | |
| def word_count line | |
| counter = Hash.new(0) | |
| line.chomp.split("").each do |w| | |
| counter[w] += 1 | |
| end | |
| counter | |
| end | |
| word_count_list = [] | |
| $stdin.read.lines do |line| | |
| word_count_list << word_count(line) | |
| end | |
| question = "片方がもう片方の並び替えになっているか:" | |
| if word_count_list.uniq.size == 1 | |
| puts question + "Yes" | |
| elsif | |
| puts question + "No" | |
| end |
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
| puts $stdin.read.gsub(/\s/, "%20") |
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
| ary = [] | |
| result = "" | |
| inputs = $stdin.read | |
| inputs.split("").each do |w| | |
| if ary.empty? | |
| ary.push(w) | |
| elsif ary.first == w | |
| ary.push(w) | |
| else | |
| result += "#{ary.first}#{ary.size.to_s}" | |
| ary.clear | |
| ary.push(w) | |
| end | |
| end | |
| if result.gsub(/1/, "") == inputs.chomp | |
| puts inputs | |
| else | |
| puts result | |
| end |
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
| strs = $stdin.read.split("\n") | |
| if (strs[0]*2).sub(strs[1], "") == strs[0] | |
| puts "s1はs2を回転させた文字列です" | |
| else | |
| puts "s1はs2を回転させた文字列ではありません" | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment