题解 | #shell格式化输出#
格式化输出
http://www.nowcoder.com/practice/d91a06bfaff443928065e611b14a0e95
#! /usr/bin/env bash
########################################################
#
#
########################################################
function solution_1() {
while read line; do
printf "%'d\n" ${line}
done < nowcoder.txt
}
########################################################
#
#
########################################################
function solution_2() {
local length=0
while read line; do
length=${#line}
if [ ${length} <= 3 ]; then
echo "line"
fi
local str=""
local temp=0
while [[ length > 3 ]]; do
str=${string: ${temp} : 3}
done
done < nowcoder.txt
}
########################################################
#
#
########################################################
function solution_3() {
local length=0
while read line; do
length=${#line}
if [ ${length} <= 3 ]; then
echo "line"
continue
fi
local temp=0
local str=""
for (( i=$length-1; i>=0; i-- )); do
((temp++))
str=${"${line}" : : }
if [[ $(($temp%3)) = 0 ]]; then
:
fi
done
done < nowcoder.txt
}
solution_1