第2题
chomp($str=<STDIN>);
my @array=split/[ ,]/,$str;
my $mx = $array[0];
for my $e(@array) {$mx = $e if ($e > $mx);}
print "最大值为$mx";
第3题
chomp($str=<STDIN>);
my @array=split/[ ,]/,$str;
my @sorted_num=sort{$a<=>$b}@array;
my $string=join(",",@sorted_num);
print "排序后的数列为:$string";
第4题
chomp($str=<STDIN>);
my @array=split//,$str;
my %ha;
my @uniq=grep{++$ha{$_}<2}@array;
my $size=@array;
my $n;my $foundno;my $regex;my $freq;
print "氨基酸\t频数\t频率\n";
for($n=0;$n<@uniq;$n++){
$regex=@uniq[$n];
$foundno=0;
$foundno++ while($str=~m/$regex/g);
$freq=$foundno*100/$size;
print "$regex\t$foundno\t$freq%\n";
}
#!/usr/bin/perl -w
use strict;
use warnings;
my %element;
my $count=1;
open IN_Z,"z.txt";
open IN_OJ,"OJ.txt";
open OUT_FILE,">OJ_OUT.txt";
while(<IN_Z>){
my @array=split;
$element{$array[1]}=join(",",@array[3..7]);
}
while(<IN_OJ>){
my @array_oj=split;
foreach my $word (@array_oj){
if($element{$word}){
my @out_data=split(",",$element{$word});
foreach my $i (0..4){
print OUT_FILE $count.":".$out_data[$i]."\t";
$count++;
}
}
else{
foreach (0..4){
print OUT_FILE $count.":"."0"."\t";
$count++;
}
}
}
print OUT_FILE "\n";
}
close IN_Z;
close IN_OJ;
close OUT_FILE;