- 论坛徽章:
- 0
|
回复 1# cjaizss
根据cjaizss提供的代码思路,稍加改编,简化了下代码~那个lookup table是用shell脚本生成的,语法与之前的一样~- #!/bin/sed -nrf
- s/^0*([0-9]+)\s+0*([0-9]+)\s*$/m\1xm\2ymamb/;ta
- s/.*/input error/;by
- :a
- s/mxmy//;td
- s/mx/mx/;tc
- s/my/my/;tb
- #the length of two number is equal
- s/m([0-9]*)(.)xm([0-9]*)(.)ym([0-9]*)am([0-9]*)b/m\1xm\3ym\2\5am\4\6b/;ta
- :b
- #the second number is shorter, append 0 before it
- s/m([0-9]*)(.)xmym([0-9]*)am([0-9]*)b/m\1xmym\2\3am0\4b/;ta
- :c
- #the first number is shorter, append 0 before it
- s/m([0-9]*)(.)ym([0-9]*)am([0-9]*)b/m\1ym0\3am\2\4b/;ta
- :d
- #lookup table
- s/(.*)/\10d\
- 000a0b0d010a1b0d020a2b0d030a3b0d040a4b0d050a5b0d060a6b0d070a7b0d080a8b0d090a9b0d\
- 011a0b0d021a1b0d031a2b0d041a3b0d051a4b0d061a5b0d071a6b0d081a7b0d091a8b0d101a9b0d\
- 022a0b0d032a1b0d042a2b0d052a3b0d062a4b0d072a5b0d082a6b0d092a7b0d102a8b0d112a9b0d\
- 033a0b0d043a1b0d053a2b0d063a3b0d073a4b0d083a5b0d093a6b0d103a7b0d113a8b0d123a9b0d\
- 044a0b0d054a1b0d064a2b0d074a3b0d084a4b0d094a5b0d104a6b0d114a7b0d124a8b0d134a9b0d\
- 055a0b0d065a1b0d075a2b0d085a3b0d095a4b0d105a5b0d115a6b0d125a7b0d135a8b0d145a9b0d\
- 066a0b0d076a1b0d086a2b0d096a3b0d106a4b0d116a5b0d126a6b0d136a7b0d146a8b0d156a9b0d\
- 077a0b0d087a1b0d097a2b0d107a3b0d117a4b0d127a5b0d137a6b0d147a7b0d157a8b0d167a9b0d\
- 088a0b0d098a1b0d108a2b0d118a3b0d128a4b0d138a5b0d148a6b0d158a7b0d168a8b0d178a9b0d\
- 099a0b0d109a1b0d119a2b0d129a3b0d139a4b0d149a5b0d159a6b0d169a7b0d179a8b0d189a9b0d\
- 010a0b1d020a1b1d030a2b1d040a3b1d050a4b1d060a5b1d070a6b1d080a7b1d090a8b1d100a9b1d\
- 021a0b1d031a1b1d041a2b1d051a3b1d061a4b1d071a5b1d081a6b1d091a7b1d101a8b1d111a9b1d\
- 032a0b1d042a1b1d052a2b1d062a3b1d072a4b1d082a5b1d092a6b1d102a7b1d112a8b1d122a9b1d\
- 043a0b1d053a1b1d063a2b1d073a3b1d083a4b1d093a5b1d103a6b1d113a7b1d123a8b1d133a9b1d\
- 054a0b1d064a1b1d074a2b1d084a3b1d094a4b1d104a5b1d114a6b1d124a7b1d134a8b1d144a9b1d\
- 065a0b1d075a1b1d085a2b1d095a3b1d105a4b1d115a5b1d125a6b1d135a7b1d145a8b1d155a9b1d\
- 076a0b1d086a1b1d096a2b1d106a3b1d116a4b1d126a5b1d136a6b1d146a7b1d156a8b1d166a9b1d\
- 087a0b1d097a1b1d107a2b1d117a3b1d127a4b1d137a5b1d147a6b1d157a7b1d167a8b1d177a9b1d\
- 098a0b1d108a1b1d118a2b1d128a3b1d138a4b1d148a5b1d158a6b1d168a7b1d178a8b1d188a9b1d\
- 109a0b1d119a1b1d129a2b1d139a3b1d149a4b1d159a5b1d169a6b1d179a7b1d189a8b1d199a9b1d\
- cc/
- :e
- #plus two numbers from the end of themselves
- s/(.)am([0-9]*)(.)b(.)d(.*)(.)(.)\1a\3b\4d(.*)c(.*)c/am\2b\6d\5\6\7\1a\3b\4d\8c\7\9c/;te
- :x
- #get the result
- s/^mamb(.)d.+c(.+)c/\1\2/;tx
- #remove leading zero
- s/^0*//;ty
- :y
- p
复制代码 |
|