This topic has been archived. It cannot be replied.
-
工作学习 / 专业技术讨论 / 贴个unix shell环境的小题目给大家玩玩儿。
输入变量为一不超过10位的整数。要求输出值在输入值pad leading zero to make the length
to 10. 看看谁的办法最简洁。
要求:不用使用文件,可以使用管道(pipe).my solution is:
outvar=`echo $invar|sed -e 's/\(^.$\)/000000000\1/' -e 's/\(^..$\)/00000000\1/' -e 's/\(^...$\)/0000000\1/' -e 's/\(^....$\)/000000\1/' -e 's/\(^.....$\)/00000\1/' -e 's/\(^......$\)/0000\1/' -e 's/\(^.......$\)/000\1/' -e 's/\(^........$\)/00\1/' -e 's/\(^.........$\)/0\1/'`
-647i(流浪的步行万里);
2007-5-3
{357}
(#3651153@0)
-
how about -- printf "%.10d" $invar
-onboard(Write it down);
2007-5-3
(#3651221@0)
-
en. good, better than mine: outvar=`echo $invar|awk '{printf("%.10d", $1)}'`
-647i(流浪的步行万里);
2007-5-3
(#3651255@0)
-
what's the prize? ^_^
-onboard(Write it down);
2007-5-3
(#3651267@0)
-
en... u can ask.
-647i(流浪的步行万里);
2007-5-3
(#3651285@0)
-
那就再来一道吧...:D
-onboard(Write it down);
2007-5-3
(#3651305@0)
-
ok. i have another one. it is little bit harder. about csv file re-orginze.
-647i(流浪的步行万里);
2007-5-3
{790}
(#3651939@0)
-
it looks this time no more prize ;)
-647i(流浪的步行万里);
2007-5-3
(#3652503@0)
-
Couldn't google an answer this time :( 作为惩罚就再来一道吧...:D
-onboard(Write it down);
2007-5-4
(#3652969@0)
-
It is your turn now. 作为惩罚you来一道吧
-647i(流浪的步行万里);
2007-5-4
(#3653179@0)
-
太复杂。转成string后,前面加10个0,然后取右边10位就行了。
-bdbs(不多不少);
2007-5-3
(#3651319@0)
-
回得太快了,没看到楼上的解答。:)
-bdbs(不多不少);
2007-5-3
(#3651323@0)