最新消息:XAMPP默认安装之后是很不安全的,我们只需要点击左方菜单的 "安全"选项,按照向导操作即可完成安全设置。

Day 16

XAMPP下载 admin 575浏览 0评论
 Day 18: Queues and Stacks
# create the Solution class
class Solution
def initialize
@stack =”
@queue=”
end

def push_character c
@stack += c if c!=”\n”
end

def enqueue_character c
@queue += c if c!=”\n”
end

def dequeue_character
@queue.reverse
end

def pop_character
@stack
end
end

# create Solution class object
solution = Solution.new

# read the input
input = gets

input.split(”).each do |c|
# push the character to stack
solution.push_character c

# enqueue the character to queue
solution.enqueue_character c
end

# check if input string is palindrome or not
is_palindrome = true

(input.length / 2).times do
if solution.pop_character != solution.dequeue_character
is_palindrome = false
break
end
end

# print if string is palindrome or not
if is_palindrome
puts “The word, #{input}, is a palindrome.”
else
puts “The word, #{input}, is not a palindrome.”
end

转载请注明:XAMPP中文组官网 » Day 16

您必须 登录 才能发表评论!