num_n50.pl 505 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/perl -w
  2. #
  3. # Author: Ruan Jue
  4. #
  5. use strict;
  6. my $total = 0;
  7. my @nums = ();
  8. my $len = 0;
  9. while(<>){
  10. next unless(/(\d+)/);
  11. push(@nums, $1),$total+=$1 if($1);
  12. }
  13. print "Total: $total\n";
  14. my @nxxs = ();
  15. for(my $i=0;$i<=10;$i++){
  16. push(@nxxs, int($total*$i*0.1));
  17. }
  18. push(@nxxs, $total + 1);
  19. my $i = 0;
  20. my $j = 0;
  21. @nums = sort {$b <=> $a} @nums;
  22. $len = 0;
  23. for(;$i<@nums;$i++){
  24. $len += $nums[$i];
  25. while($nxxs[$j] <= $len){
  26. print "N".$j."0: $nums[$i]\t" . ($i + 1) . "\n";
  27. $j ++;
  28. }
  29. }
  30. 1;