blob: c2409d1c8cf03870d58974eee8a91d5553b51bd8 (
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
|
# Task 1: Keyboard Word
# Submitted by: Mohammad S Anwar
#
# You are given an array of words.
# Write a script to print all the words in the given array that can be types using alphabet on only one row of the keyboard.
#
# Let us assume the keys are arranged as below:
# Row 1: qwertyuiop
# Row 2: asdfghjkl
# Row 3: zxcvbnm
#
# Example 1
# Input: @words = ("Hello","Alaska","Dad","Peace")
# Output: ("Alaska","Dad")
#
# Example 2
# Input: @array = ("OMG","Bye")
# Output: ()
def main(input)
a_class = ['qwertyuiop','asdfghjkl','zxcvbnm']
output = []
input.each {|word|
a_class.each {|re|
if word.match?(/^[#{re}]+$/i)
output.append(word)
break
end
}
}
printf "Output: (%s)\n", output.join(', ')
end
main ARGV
|