- 论坛徽章:
- 0
|
原帖由 hitsubunnu 于 2009-3-19 10:29 发表
use List::Util qw(max);
my $str = 'hellooloooooo';
my (%h,%f);
$f{++$h{$_}}=$_ for split //,$str;
print $f{max keys %f};
看不懂perl的,不妨看看ruby怎么实现的
def count(a)
result =[]
a.uniq.each do|x|
result << [x,a.grep(x).length]
end
result.max { |a, b| a[1]<=>b[1] }
end
s = "aadddeegggggg"
str = s.scan(/w{1}/)
p count(str) |
|
|