Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- use utf8;
- use open qw(:std :encoding(utf8));
- use feature q(say);
- sub Compare($$);
- sub Rate($$);
- my $s1 = 'あいう1';
- my $s2 = 'あいえ23';
- say Rate($s1, $s2) . '%';
- sub Compare($$) {
- my ($s1, $s2) = @_;
- my $len1 = length $s1;
- for (my $i = $len1; $i > 0; --$i) {
- for (my $j = 0; $i + $j <= $len1; ++$j) {
- return $i if $s2 =~ substr $s1, $j, $i;
- }
- }
- return 0;
- }
- sub Rate($$) {
- my ($s1, $s2) = @_;
- return Compare($s1, $s2) * 100.0 / (length $s2);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement