def sort( arr)
n = arr.length - 1
for i in 0 ..n - 1
min = arr[ i]
pos = i
for j in i+ 1 ..n
if arr[ j] .to_i < min.to_i
min = arr[ j]
pos = j
end
end
aux = arr[ pos]
arr[ pos] = arr[ i]
arr[ i] = aux
end
end
def main( )
arr = [ 1 ,12 ,- 1 ,8 ,41 ,5 ,71 ,- 1 ,41 ,8 ,10 ,41 ,- 1 ,1 ]
p arr
freq = [ ]
vec = [ ]
sort( arr)
k = 0
vec[ k] = arr[ k]
freq[ k] = 1
for i in 0 ..arr .length - 1
if arr[ i] == arr[ i+ 1 ]
freq[ k] + = 1
else
k + = 1
vec[ k] = arr[ i+ 1 ]
freq[ k] = 1
end
end
for i in 0 ..k - 1
if freq[ i] == 1
print "Elementul " , vec[ i] , " apare o singura data! \n "
else
print "Elementul " , vec[ i] , " apare de " , freq[ i] , " ori!\n "
end
end
end
main( )
ZGVmIHNvcnQoYXJyKQogICAgbiA9IGFyci5sZW5ndGggLSAxCiAgICBmb3IgaSBpbiAwLi5uLTEKICAgICAgICAgbWluID0gYXJyW2ldCiAgICAgICAgIHBvcyA9IGkKICAgICAgICAgZm9yIGogaW4gaSsxLi5uCiAgICAgICAgICAgICBpZiBhcnJbal0udG9faSA8IG1pbi50b19pCiAgICAgICAgICAgICAgICBtaW4gPSBhcnJbal0KICAgICAgICAgICAgICAgIHBvcyA9IGoKICAgICAgICAgICAgIGVuZAogICAgICAgICBlbmQKICAgICAgICAgYXV4ID0gYXJyW3Bvc10KICAgICAgICAgYXJyW3Bvc10gPSBhcnJbaV0KICAgICAgICAgYXJyW2ldID0gYXV4CiAgICBlbmQKZW5kCmRlZiBtYWluKCkKICAgIGFyciA9IFsxLDEyLC0xLDgsNDEsNSw3MSwtMSw0MSw4LDEwLDQxLC0xLDFdCiAgICBwIGFycgogICAgZnJlcSA9IFtdCiAgICB2ZWMgPSBbXQogICAgc29ydChhcnIpCiAgICBrID0gMAogICAgdmVjW2tdID0gYXJyW2tdCiAgICBmcmVxW2tdID0gMQogICAgZm9yIGkgaW4gMC4uYXJyLmxlbmd0aC0xCiAgICAgICAgaWYgYXJyW2ldID09IGFycltpKzFdCiAgICAgICAgICAgZnJlcVtrXSArPSAxCiAgICAgICAgZWxzZQogICAgICAgICAgayArPSAxCiAgICAgICAgICB2ZWNba10gPSBhcnJbaSsxXQogICAgICAgICAgZnJlcVtrXSA9IDEKICAgICAgICBlbmQKICAgIGVuZAogICAgZm9yIGkgaW4gMC4uay0xCiAgICAgICAgaWYgZnJlcVtpXSA9PSAxCiAgICAgICAgICBwcmludCAiRWxlbWVudHVsICIgLCB2ZWNbaV0gLCAiIGFwYXJlIG8gc2luZ3VyYSBkYXRhISBcbiIKICAgICAgICBlbHNlCiAgICAgICAgICBwcmludCAiRWxlbWVudHVsICIgLCB2ZWNbaV0gLCAiIGFwYXJlIGRlICIgLCBmcmVxW2ldICwgIiBvcmkhXG4iCiAgICAgICAgZW5kCiAgICBlbmQKZW5kCm1haW4oKQo=
stdout
[1, 12, -1, 8, 41, 5, 71, -1, 41, 8, 10, 41, -1, 1]
Elementul -1 apare de 3 ori!
Elementul 1 apare de 2 ori!
Elementul 5 apare o singura data!
Elementul 8 apare de 2 ori!
Elementul 10 apare o singura data!
Elementul 12 apare o singura data!
Elementul 41 apare de 3 ori!
Elementul 71 apare o singura data!