--------------------------------------------------------------------------------------------------------------
#!/bin/bin/perl
use strict;
use warnings;
my $palavra = shift or die $!;
my @array = split(//,$palavra);
my ($max,$valida) = ($#array,0);
for(my $i = 0; $i <= $#array/2; $i++ ){
if($array[$i] eq $array[$max]){
$valida ++;
}
$max --;
}
if($valida >= ($#array/2) ){
print "@array:\tPalindromo YES\n";
}else{
print "@array:\tPalindromo NO\n";
}
--------------------------------------------------------------------------------------------------------------
:~> perl validate.pl arara
a r a r a: Palindromo YES
:~> perl validate.pl arar
a r a r: Palindromo NO
:~> perl validate.pl tenet
t e n e t: Palindromo YES
:~> perl validate.pl tene
t e n e: Palindromo NO
0 comentários:
Post a Comment