level 3
用lua写这个怎么写,在一个字符串中找到第一个只出现一次的,如输出abacccdeff则输出b,急求大神
2015年01月14日 07点01分
1
level 1
function only_once(s)
local res={}
local once_a={}
for _,k in pairs(s) do
res[k]=res[k]+1
else res[k]=1 end
end
for k,v in pairs(res) do
if(res[k]==1) then
print(k) end
end
end
我今天才开始学这个语言,写的丑些请见谅,
2015年01月14日 08点01分
2
level 3
function getfirst(s)
if 'string' ~= type(s) then
return false
end
local tmp_word = ''
local final_word = ''
for i=1,#s do
local x=0
tmp_word = s:sub(i,i)
for k in s:gmatch(tmp_word) do
x=x+1
end
if x == 1 then
final_word = tmp_word
break
end
end
return final_word
end
2015年01月20日 02点01分
3
level 7
还可以更简单一点
s = 'aabacc'
for i=1,#s do
_,times = s:gsub(s:sub(i,i), '')
if times == 1 then
print(s:sub(i,i))
break
end
end
2015年01月28日 05点01分
4