#!C:\Perl\bin\perl -w
use strict;
use warnings;
my @array;
open(my $fh,"<","votes.txt") or die;
while(<$fh>)
{
chomp;
push @array,$_;
}
my $hello=chr(65);
print "HELLO:$hello\n";
my $arraynum=$#array;
my $one="Ken Myer";
my $cone=0;
my $rone;
my $two="Jonathan Haas";
my $ctwo=0;
my $rtwo;
my $three="Pilar Ackerman";
my $cthree=0;
my $rthree;
my $four="Syed Abbas";
my $cfour=0;
my $rfour;
my $current;
my $delname1;
my $delname2;
my @delname; # 存放被删除的名字
sub get
{
$cone=0;
$ctwo=0;
$cthree=0;
$cfour=0;
foreach (@array)
{
$current=$_;
chomp($current);
chomp($one);
if($current =~ /^$one/)
{
$cone=$cone+1;
}
if($current =~ /^$two/)
{
$ctwo=$ctwo+1;
}
if($current =~ /^$three/)
{
$cthree=$cthree+1;
}
if($current =~ /^$four/)
{
$cfour=$cfour+1;
}
}
$rone=$cone/($cone+$ctwo+$cthree+$cfour)*100;
$rtwo=$ctwo/($cone+$ctwo+$cthree+$cfour)*100;
$rthree=$cthree/($cone+$ctwo+$cthree+$cfour)*100;
$rfour=$cfour/($cone+$ctwo+$cthree+$cfour)*100;
}
my $arr_num ;
my $i=3;
my ($big_rate,$big_name,$small_rate,$small_name);
my $xuhao;
for ($i = 3;$i >= 0;$i--)
{
&get;
my @array_2;
$array_2[0]=$rone.",".$one;
$array_2[1]=$rtwo.",".$two;
$array_2[2]=$rthree.",".$three;
$array_2[3]=$rfour.",".$four;
my @arr=reverse sort(@array_2);
$arr_num = $#arr;
($big_rate,$big_name)=split(/,/,$arr[0]);
if ($big_rate < 50 )
{
($small_rate,$small_name)=split(/,/,$arr[$i]);
$xuhao=3-$i;
$delname[$xuhao]=$small_name.",";
# 把数组array里的这个最小的去掉。
foreach(@delname)
{
my $nowdel=$_;
}
my $delnym=$#delname;
$delname1=$delname[0];
if ($delnym >= 1){ $delname2=$delname[1];}
foreach (@array)
{
my $test=$small_name.",";
if ($delnym >= 1)
{
eval "s/^$delname2//g" ;
}
eval "s/^$delname1//g";
}
}
else
{
printf "\n##################\n THE victory belong to $big_name,the rate is: %.2f % \n##################\n",$big_rate;
exit 0;
}
for (my $j = 0;$j <= $#arr ; $j++)
{
pop @arr;
}
}
阅读(1312) | 评论(0) | 转发(0) |