Skip to content

Latest commit

 

History

History
23 lines (21 loc) · 365 Bytes

40.md

File metadata and controls

23 lines (21 loc) · 365 Bytes

题目要求

输入一串随机数字,然后按千分位输出。   比如输入数字串为“123456789”,输出为123,456,789。

参考答案

#!/bin/bash
n=`echo $1|wc -L`
for d in `echo $1|sed 's/./& /g'`
do
    n2=$[$n%3]
    if [ $n2 -eq 0 ]
    then
	echo -n ",$d"
    else
	echo -n "$d"
    fi
    n=$[$n-1]
done |sed 's/^,//'
echo