summaryrefslogtreecommitdiff
path: root/hw5/hw5.lua
blob: b1fa6f3a35cbf741d2265fb104cd09dd589e092c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
local accept_input = io.read
local split_string
split_string = function(s)
  local _accum_0 = { }
  local _len_0 = 1
  for x in string.gmatch(s, "(%S+)") do
    _accum_0[_len_0] = x
    _len_0 = _len_0 + 1
  end
  return _accum_0
end
local capitalize_word
capitalize_word = function(word)
  return string.gsub(word, "^(.)", string.upper)
end
local uppercase_words
uppercase_words = function(array)
  local _accum_0 = { }
  local _len_0 = 1
  for _index_0 = 1, #array do
    local word = array[_index_0]
    _accum_0[_len_0] = capitalize_word(word)
    _len_0 = _len_0 + 1
  end
  return _accum_0
end
local print_words
print_words = function(array)
  for _index_0 = 1, #array do
    local word = array[_index_0]
    print(word)
  end
end
local sort_words = table.sort
local sentence = accept_input()
local words = split_string(sentence)
words = uppercase_words(words)
sort_words(words)
return print_words(words)