原帖:
处理前:
ABDCDCDCAAXCXCDCCABABDCDCDCAABXBABDCDCDCAABBCDCCAXDBBXABDCDCDCAABBCDXCCA
BBCDCCABBBABXCDCDCAABBCDXCCABBBBBABDCDCDCAABBCDCCAXBBBABCDAAAXBCDADCAXXX
XABCDCDCAAXBBCCDCCABABDCDCDCAABXBABDABACCCAXCDCDCAABBCDCCABBBXABDCDCDCAA
AACDCCAADCABDCDCDCAABXCDXCXABCDDBABDCDCDCAABBXBXCAABBBABCDAAAXBCDADCABBB
ADCAAAAAXABCDCCCCCDCABXBBCCDCCABABDCDCDCAABXBABDABDCCCAXCDCDCAAAAABBCDCC
XCCCAABDCAAXXAADCCCCCCAACCAAAAAAAAAXBBDCCXACDACDAAXCBBBBBBBAAABCADDCAAXC
XABCDCDCAAXBBCCDCCABABDCDCDCAABXBABDABACCCAXCDCDCAABBCDCCABBBXABDCDCDCAA
处理后:
aBDCDCDCaaxcxcdcCABABDCDcDcAabxbaBDCDCDCAABbCdCcaxdbbxaBDCDCDcAAbbcdxcca
bBCDCCABbBabxcdcDCAAbbcdxccaBBbbBABDCDCDCAAbBcDcCaxbbbABCDAAaxbcDADCaxxx
xaBCDCDCaaxbbCCDCCABAbdCdCdCAabxbaBdABACCCaxcdcdCAaBBcDcCABbbxaBDCDCDcaa
aACDCCAAdCabdCDCDCAabxcdxcxaBCDdBABdCDCDCAAbbxbxcaaBBBAbCDAAaxbcDADCAbbB
aDCAAAAaxaBcdCCCCCDCabxbbCcDCCAbABDcDCDCAabxbaBdABdCCCaxcdcDCaAAAABBCdcC
xcccAABDcAaxxaADCCCCCcaAcCaAAAAaAAaxbbdccxacDACdAaxcbbBbBBBAAaBCADDCAaxc
xaBCDCDCaaxbbCCDCCABABDCDCdCAabxbaBdABACCcaxcdcdCAaBBCDcCABbbxaBDCDCDCaA
处理规则:
数据中的字符X为污染源,纯净的字符为A、B、C、D,我们需要根据X附近(上、下、左、右四个方向)的字符来转化受到污染的字符,A、B、C、D分别代表1、2、3、4长度,例如X左边的字符是A,就表示左边有一个字符被污染了,需要将它转化为小写,如果左边的字符是B,就表示有两个字符被污染,需要把它们转化为小写,但有一种特殊情况,就是遇到字符X时就不需要再继续转化了,其他几个方向同理。如果看不懂我说的可以看看原帖。
-
#楼主给的数据
-
[root@localhost ~]# cat i
-
ABDCDCDCAAXCXCDCCABABDCDCDCAABXBABDCDCDCAABBCDCCAXDBBXABDCDCDCAABBCDXCCA
-
BBCDCCABBBABXCDCDCAABBCDXCCABBBBBABDCDCDCAABBCDCCAXBBBABCDAAAXBCDADCAXXX
-
XABCDCDCAAXBBCCDCCABABDCDCDCAABXBABDABACCCAXCDCDCAABBCDCCABBBXABDCDCDCAA
-
AACDCCAADCABDCDCDCAABXCDXCXABCDDBABDCDCDCAABBXBXCAABBBABCDAAAXBCDADCABBB
-
ADCAAAAAXABCDCCCCCDCABXBBCCDCCABABDCDCDCAABXBABDABDCCCAXCDCDCAAAAABBCDCC
-
XCCCAABDCAAXXAADCCCCCCAACCAAAAAAAAAXBBDCCXACDACDAAXCBBBBBBBAAABCADDCAAXC
-
XABCDCDCAAXBBCCDCCABABDCDCDCAABXBABDABACCCAXCDCDCAABBCDCCABBBXABDCDCDCAA
-
-
#awk脚本1(用于横向标示杂质)
-
[root@localhost ~]# cat a1
-
#!/bin/awk -f
-
BEGIN{
-
FS=OFS="";
-
IGNORECASE=1;
-
a["a"]=a["A"]=1;
-
a["b"]=a["B"]=2;
-
a["c"]=a["C"]=3;
-
a["d"]=a["D"]=4;
-
}
-
{
-
for(i=1;i<=NF;i++){
-
if($i=="X"){
-
for(j=i-1;j>=i-a[$(i-1)]&&j>=1;j--){
-
if($j=="X")break;
-
$j=tolower($j)
-
}
-
for(j=i+1;j<=i+a[$(i+1)]&&j<=NF;j++){
-
if($j=="X")break;
-
$j=tolower($j)
-
}
-
$i=tolower($i)
-
}
-
}
-
}
-
1
-
-
#awk脚本2(用于行列转换)
-
[root@localhost ~]# cat a2
-
#!/bin/awk -f
-
BEGIN{
-
FS=""
-
}
-
{
-
for(i=1;i<=NF;i++)a[i]=a[i]$i
-
}
-
END{
-
for(i=1;i<=NF;i++)print a[i]
-
}
-
-
#运行方法和结果(运行前先赋予脚本a1和a2可执行权限)
-
[root@localhost ~]# ./a1 i | ./a2 | ./a1 | ./a2
-
aBDCDCDCaaxcxcdcCABABDCDcDcAabxbaBDCDCDCAABbCdCcaxdbbxaBDCDCDcAAbbcdxcca
-
bBCDCCABbBabxcdcDCAAbbcdxccaBBbbBABDCDCDCAAbBcDcCaxbbbABCDAAaxbcDADCaxxx
-
xaBCDCDCaaxbbCCDCCABAbdCdCdCAabxbaBdABACCCaxcdcdCAaBBcDcCABbbxaBDCDCDcaa
-
aACDCCAAdCabdCDCDCAabxcdxcxaBCDdBABdCDCDCAAbbxbxcaaBBBAbCDAAaxbcDADCAbbB
-
aDCAAAAaxaBcdCCCCCDCabxbbCcDCCAbABDcDCDCAabxbaBdABdCCCaxcdcDCaAAAABBCdcC
-
xcccAABDcAaxxaADCCCCCcaAcCaAAAAaAAaxbbdccxacDACdAaxcbbBbBBBAAaBCADDCAaxc
-
xaBCDCDCaaxbbCCDCCABABDCDCdCAabxbaBdABACCcaxcdcdCAaBBCDcCABbbxaBDCDCDCaA
-
[root@localhost ~]# cat a
-
#!/bin/awk
-
BEGIN{
-
FS="";
-
IGNORECASE=1;
-
a["a"]=a["A"]=1;
-
a["b"]=a["B"]=2;
-
a["c"]=a["C"]=3;
-
a["d"]=a["D"]=4
-
}
-
{
-
for(i=1;i<=NF;i++)b[NR,i]=$i
-
}
-
END{
-
for(i=1;i<=NR;i++){
-
for(j=1;j<=NF;j++){
-
if(b[i,j]=="X"){
-
for(k=j-1;k>=j-a[b[i,j-1]]&&k>=1;k--){
-
if(b[i,k]=="X")break;
-
b[i,k]=tolower(b[i,k])
-
}
-
for(k=j+1;k<=j+a[b[i,j+1]]&&k<=NF;k++){
-
if(b[i,k]=="X")break;
-
b[i,k]=tolower(b[i,k])
-
}
-
b[i,j]=tolower(b[i,j])
-
}
-
}
-
}
-
for(i=1;i<=NF;i++){
-
for(j=1;j<=NR;j++){
-
if(b[j,i]=="X"){
-
for(k=j-1;k>=j-a[b[j-1,i]]&&k>=1;k--){
-
if(b[k,i]=="X")break;
-
b[k,i]=tolower(b[k,i])
-
}
-
for(k=j+1;k<=j+a[b[j+1,i]]&&k<=NR;k++){
-
if(b[k,i]=="X")break;
-
b[k,i]=tolower(b[k,i])
-
}
-
b[j,i]=tolower(b[j,i])
-
}
-
}
-
}
-
for(i=1;i<=NR;i++){
-
for(j=1;j<NF;j++)printf b[i,j];
-
print b[i,NF]
-
}
-
}
其他人的代码请看原帖。
阅读(1192) | 评论(0) | 转发(0) |