Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2013-12-24代码游戏 之 乱排书【难度中】 #20

Open
chenkan opened this issue Dec 23, 2013 · 2 comments
Open

2013-12-24代码游戏 之 乱排书【难度中】 #20

chenkan opened this issue Dec 23, 2013 · 2 comments

Comments

@chenkan
Copy link
Owner

chenkan commented Dec 23, 2013

猴版

写个函数,给定一个字符串列表之后按下面格式打印出来,一行一个打印在矩形框中。
例如,列表["Hello", "World", "in", "a", "frame"]打印的结果是:

*********
* Hello *
* World *
* in    *
* a     *
* frame *
*********

虎版

*******
*faiWH*
*r noe*
*a  rl*
*m  ll*
*e  do*
*******

龙版

   好不威风
脚            拳
踢            打
西            南
湖            山
托            敬
儿            老
所            院

自虐版
使用VIM等文本编辑器实现

@chenkan
Copy link
Owner Author

chenkan commented Dec 26, 2013

#encoding: utf-8

# 虎版
MAX_LENGTH = 5
input = ["hello", "world", "in", "a", "frame"]

input.map! {|x| x + " "* (MAX_LENGTH - x.size)}
input.map! {|x| "*" + x + "*"}
input = ["*" * (MAX_LENGTH + 2) ] + input + ["*" * (MAX_LENGTH + 2) ]
input.map! {|x| x.split("")}
input = input.transpose

input.each do |x|
  puts x.join.reverse!
end

# 龙版
a = " 拳打南山敬老院"
c4 = "好       "
c3 = "不       "
c2 = "威       "
c1 = "风       "
b = " 脚踢西湖托儿所"

input = [a, c1, c2, c3, c4, b]
input.map! {|x| x.split("")}
input = input.transpose
input.each do |x|
  puts x.join.reverse!
end

@chenkan chenkan closed this as completed Dec 26, 2013
@chenkan chenkan reopened this Dec 26, 2013
@hzhuangqingbin
Copy link

#encoding: utf-8
puts "猴版"

strs = ["Hello", "World", "in", "a", "frame"]
strs = ["Merry ", "Christmas", "for", "Everyone"]
strs = ["Wish ", "BlackQA", "Happy", "New", "Year"]
max = 0
strs.each do |str|
  if max < str.size
    max = str.size
  end
end
puts ('*')*(max+4)
strs.each do |str|
print ('* ')
print str
print (' ')*(max - str.size)
puts (' *')
end
puts ('*')*(max+4)

#encoding: utf-8
puts "虎版"

strs = ["Hello", "World", "in", "a", "frame"]
strs = ["Merry ", "Christmas", "for", "Black"]
strs = ["Wish ", "BlackQA", "Happy", "New", "Year"]

col = strs.size

max = 0
strs.each do |str|
  if max < str.size
    max = str.size
  end
end

puts ('*')*(col+4)
for i in 0..max-1 do
  print('* ')
  for str in strs.reverse do
    print(str[i] || ' ')
  end
  puts(' *')
end
puts ('*')*(col+4)

#encoding: utf-8
puts "龙版"

strs = ["好不威风", "脚踢西湖托儿所", "拳打南山敬老虎"]
strs = ["黑手党", "天王盖地虎", "宝塔镇河妖"]

col = strs[0].size
row = strs[1].size

puts("  #{strs[0]}  ")
for i in 0.. row-1 do
  print("#{strs[1][i]}")
  print(' '*(col*2))
  print("#{strs[2][i]}")
  puts
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants