Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
21
Task/Abbreviations-automatic/Perl/abbreviations-automatic.pl
Normal file
21
Task/Abbreviations-automatic/Perl/abbreviations-automatic.pl
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
use strict;
|
||||
use utf8;
|
||||
binmode STDOUT, ":utf8";
|
||||
|
||||
sub auto_abbreviate {
|
||||
my($string) = @_;
|
||||
my @words = split ' ', $string;
|
||||
my $max = 0;
|
||||
return '' unless @words;
|
||||
map { $max = length($_) if length($_) > $max } @words;
|
||||
for $i (1..$max) {
|
||||
my %seen;
|
||||
return $i if @words == grep {!$seen{substr($_,0,$i)}++} @words;
|
||||
}
|
||||
return '∞';
|
||||
}
|
||||
|
||||
open $fh, '<:encoding(UTF-8)', 'DoWAKA.txt';
|
||||
while ($_ = <$fh>) {
|
||||
print "$.) " . auto_abbreviate($_) . ' ' . $_;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue