每次做完都发现别人的代码几乎只有【1 行】这也就算啦,可是这篇实在是不能忍受了!
string 可以是所有的合法字符,但是只需要转换所有字母,其他字符保持不变!
def encode(string)
#your code here
string = string.downcase
string = string.gsub(/a/,'1')
string = string.gsub(/b/,'2')
string = string.gsub(/c/,'3')
string = string.gsub(/d/,'4')
string = string.gsub(/e/,'5')
string = string.gsub(/f/,'6')
string = string.gsub(/g/,'7')
string = string.gsub(/h/,'8')
string = string.gsub(/i/,'9')
string = string.gsub(/j/,'10')
string = string.gsub(/k/,'11')
string = string.gsub(/l/,'12')
string = string.gsub(/m/,'13')
string = string.gsub(/n/,'14')
string = string.gsub(/o/,'15')
string = string.gsub(/p/,'16')
string = string.gsub(/q/,'17')
string = string.gsub(/r/,'18')
string = string.gsub(/s/,'19')
string = string.gsub(/t/,'20')
string = string.gsub(/u/,'21')
string = string.gsub(/v/,'22')
string = string.gsub(/w/,'23')
string = string.gsub(/x/,'24')
string = string.gsub(/y/,'25')
string = string.gsub(/z/,'26')
end