52 lines
770 B
Awk
52 lines
770 B
Awk
BEGIN{ RS = "" }
|
|
NR==1{
|
|
template = $0
|
|
RS ="\n"
|
|
next
|
|
}
|
|
{
|
|
pair[NR] = $1
|
|
ins[NR] = $3
|
|
}
|
|
END{
|
|
|
|
for(s=1;s<=10;s++){
|
|
sp=0; delete toins; delete st
|
|
for(i=1;i<length(template);i++){
|
|
p = substr(template,i,2)
|
|
for(k in pair){
|
|
if(pair[k]==p){
|
|
st[sp] = i
|
|
toins[sp++] = ins[k]
|
|
break
|
|
}
|
|
}
|
|
}
|
|
nt = ""
|
|
for(i=1;i<=length(template);i++){
|
|
nt = nt substr(template,i,1)
|
|
for(j in st) if(st[j]==i) nt = nt toins[j]
|
|
}
|
|
print length(nt)
|
|
template = nt
|
|
}
|
|
min = length(template)
|
|
max = 0
|
|
for(i=1;i<=length(template);i++){
|
|
c = substr(template,i,1)
|
|
count[c]++
|
|
if(count[c]>max){
|
|
max = count[c]
|
|
maxc = c
|
|
}
|
|
}
|
|
for(c in count){
|
|
if(count[c]<min){
|
|
min = count[c]
|
|
minc = c
|
|
}
|
|
}
|
|
print max, maxc, min, minc
|
|
print max-min
|
|
}
|