use strict; use warnings;
my @papera = (-1, 0,3,5,2,6,3,4,5,7,3, 5,1,2,5,7,3,5,8,5,1 ,4,3,7,4,8,4,3,3,2,2, 1,29,2,3,5,7,1,9,8,6);
my @expga = ();
my $uinp = undef;
my @ucmd = ();
my $hya = undef;
my $hda = undef;
my $hdb = undef;
my $hdm = undef;
#my @bb = (1, "sum", "_2_4_5_9"); #_2_5_2_3
#$expga[2] = \@bb;
sub squr {
my $fp = shift;
my $da = index($fp, "_", 1);
my $db = index($fp, "_", $da+1);
my $dc = index($fp, "_", $db+1);
my $xa = int(substr($fp, 1, $da-1));
my $xb = int(substr($fp, $da+1, $db-$da-1)); #heng
my $xc = int(substr($fp, $db+1, $dc-$db-1));
my $xd = int(substr($fp, $dc+1)); #shu
my @fdr = ($xa, $xb, $xc, $xd);
my $fm = \@fdr;
return $fm;
}
sub gb {
my $fn = shift;
my $fp = shift;
my $fp2 = shift;
my $wa = undef;
my $rf = 0;
if ($fn eq "sum"){
my $fm = squr($fp);
my @fdr = @$fm;
$rf = 0;
my $pa = $fdr[2];
while ($pa <= $fdr[3]){
my $pb = $fdr[0];
while ($pb <= $fdr[1]){
$wa = ($pa-1)*10+$pb;
$rf += $papera[$wa];
$pb += 1;
}
$pb = $fdr[0];
$pa += 1;
}
return $rf;
} elsif ($fn eq "avrg"){
my $fm = squr($fp);
my @fdr = @$fm;
$rf = 0;
my $pa = $fdr[2];
while ($pa <= $fdr[3]){
my $pb = $fdr[0];
while ($pb <= $fdr[1]){
$wa = ($pa-1)*10+$pb;
$rf += $papera[$wa];
$pb += 1;
}
$pb = $fdr[0];
$pa += 1;
}
$rf = $rf / ($fdr[1]-$fdr[0]+1)/($fdr[3]-$fdr[2]+1);
return $rf;
} elsif ($fn eq "count"){
my $fm = squr($fp);
my @fdr = @$fm;
$rf = 0;
my $pa = $fdr[2];
while ($pa <= $fdr[3]){
my $pb = $fdr[0];
while ($pb <= $fdr[1]){
$wa = ($pa-1)*10+$pb;
$wa = ($pa-1)*10+$pb;
if ($papera[$wa] == $fp2*1.0 ){
$rf += 1;
}
$pb += 1;
}
$pb = $fdr[0];
$pa += 1;
}
return $rf;
} elsif ($fn eq "max"){
my $fm = squr($fp);
my @fdr = @$fm;
$rf = $papera[($fdr[2]-1)*10+$fdr[0]];
my $pa = $fdr[2];
while ($pa <= $fdr[3]){
my $pb = $fdr[0];
while ($pb <= $fdr[1]){
$wa = ($pa-1)*10+$pb;
$wa = ($pa-1)*10+$pb;
if ($papera[$wa] > $rf ){
$rf = $papera[$wa];
}
$pb += 1;
}
$pb = $fdr[0];
$pa += 1;
}
return $rf;
} elsif ($fn eq "min"){
my $fm = squr($fp);
my @fdr = @$fm;
$rf = $papera[($fdr[2]-1)*10+$fdr[0]];
my $pa = $fdr[2];
while ($pa <= $fdr[3]){
my $pb = $fdr[0];
while ($pb <= $fdr[1]){
$wa = ($pa-1)*10+$pb;
$wa = ($pa-1)*10+$pb;
if ($papera[$wa] < $rf ){
$rf = $papera[$wa];
}
$pb += 1;
}
$pb = $fdr[0];
$pa += 1;
}
return $rf;
}
}
while (1){
$uinp = <STDIN>;
chomp($uinp);
@ucmd = split(/,/, $uinp);
if ($ucmd[0] eq "vw"){ # see cell's true value
$hya = index($ucmd[1], "_", 1);
$hda = int(substr($ucmd[1], 1, $hya-1));
$hdb = int(substr($ucmd[1], $hya+1));
$hdm = $hda*10+$hdb;
printf("%f\n", $papera[$hdm]);
} elsif ($ucmd[0] eq "vf"){ # see cell's expression
$hya = index($ucmd[1], "_", 1);
$hda = int(substr($ucmd[1], 1, $hya-1));
$hdb = int(substr($ucmd[1], $hya+1));
$hdm = $hda*10+$hdb;
my $utmex = $expga[int($hdm)];
my @utmep = @$utmex;
#printf($utmep[2]);
my $utss = "";
for ($hda = 0; $hda < (scalar(@utmep)/3); $hda += 3){
$utss = $utmep[$hda]."*".$utmep[$hda+1]."(".$utmep[$hda+2].")";
}
printf("%s\n", $utss);
} elsif ($ucmd[0] eq "updf"){
gb("sum", "_2_5_2_3"); # 37
gb("avrg", "_2_5_2_3"); # 4.625
gb("count", "_2_5_2_3", "7"); # 2
gb("max", "_2_5_2_3"); # 8
gb("min", "_2_5_2_3"); # 1
}
}
--
FROM 59.39.216.*