#!/bin/env perl
my @data = map {$_->[0]} sort{$a->[1] <=> $b->[1]} map{[ $_, (split)[1] ]} ;
my $line=1;
my $rank=$line;
my $flag=undef;
for (@data)
{
chomp;
if ($flag != (split)[1])
{
$flag = (split)[1];
$rank = $line;
}
print "$_\t$rank\n";
$line++;
}
__DATA__
a 0.1
b 0.3
c 0.2
d 0.3
e 0.4
#!/usr/bin/perl
my ( $i, $j ) = ( 0, 1 );
my @a = sort { $a->[1] <=> $b->[1] } map { [split] } ;
for my $r ( 1 .. @a ) {
print join( "\t", @{ $a[ $r - 1 ] }, $i == $a[ $r - 1 ][1] ? $j : $r ),
"\n";
( $i, $j ) = ( $a[ $r - 1 ][1], $r );
}
__DATA__
a 0.1
b 0.3
c 0.2
d 0.3
e 0.4
#!usr/bin/perl -w
my ($file,$out)=@ARGV;
open FILE,$file or die "$!";
open OUT,"+>$out" or die "$!";
my %count;
my %number;
my $i=1;
while (
{
chomp;
my @array =split(/\s+/,$_);
if (exists $count{$array[1]})
{
$number{"$array[0]\t$array[1]"}=$count{$array[1]};
$i++;
}
else
{
$number{"$array[0]\t$array[1]"}=$count{$array[1]}=$i;
$i++;
}
my $keys = "$array[0]\t$array[1]";
print OUT "$keys\t$number{$keys}\n";
}
close FILE;
close OUT;
考题或面试题?
先说你自己有什么思路吗