Skip to content

Instantly share code, notes, and snippets.

@dulltz
Created January 20, 2016 13:12
Show Gist options
  • Select an option

  • Save dulltz/142db5d3ba20d075bb0c to your computer and use it in GitHub Desktop.

Select an option

Save dulltz/142db5d3ba20d075bb0c to your computer and use it in GitHub Desktop.
世界で戦うプログラミング力を鍛える150問 の解答
# 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
# 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
puts $stdin.read.gsub(/\s/, "%20")
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
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