Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env perl
- use strict;
- use warnings;
- use feature q(say);
- sub delete_duplicate($);
- sub delete_duplicate($) {
- my $s = shift;
- my $len = length $s;
- my $threshold = 5;
- my $t;
- my $found = 0;
- for (my $i = $len / 2; !$found && $threshold <= $i; --$i) {
- for (my $j = 0; $i + $j <= $len; ++$j) {
- $t = substr $s, $j, $i;
- my $c = () = $s =~ /$t/g;
- if ($c > 1) {
- $found = 1;
- last;
- }
- }
- }
- return $s unless $found;
- 1 while $s =~ s/(?<=$t)(.*)$t/$1/;
- return $s;
- }
- say delete_duplicate 'aeaAwww123abcdeあいうえおwww1235www123';
- say delete_duplicate 'abcdefabcde';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement