处理前:
ABDCDCDC
处理后:
DC 3 14
AB 1 1
处理规则:
请看原帖。
-
awk -F '' -vK=2 '{for(i=1;i<=NF;i+=K){y=NF-i
点击(此处)折叠或打开
-
#!/usr/bin/perl
-
use warnings;
-
use strict;
-
use 5.010;
-
-
my %hash = ( A=>0, B=>1, C=>2, D=>3 );
-
my $str = "ABDCDCDC";
-
my $K = 2;
-
my %times;
-
my $i = 0;
-
++ $times{ substr $str, $i, $K } and $i += $K while $i < length $str;
-
map { say join "\t", @$_ } sort { $b->[1] <=> $a->[1] } map {
-
my @each = split //, $_;
-
my $sum = 0;
-
map { $sum += $hash{ $each[$_] } * 4 ** ( $#each - $_ ) } 0 .. $#each;
-
[ $_, $times{$_}, $sum ];
- } keys %times;