summaryrefslogtreecommitdiff
path: root/hw5/hw5.lua
diff options
context:
space:
mode:
Diffstat (limited to 'hw5/hw5.lua')
-rw-r--r--hw5/hw5.lua39
1 files changed, 39 insertions, 0 deletions
diff --git a/hw5/hw5.lua b/hw5/hw5.lua
new file mode 100644
index 0000000..b1fa6f3
--- /dev/null
+++ b/hw5/hw5.lua
@@ -0,0 +1,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)