题解 | #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

全部评论

相关推荐

不愿透露姓名的神秘牛友
今天 12:20
点赞 评论 收藏
分享
Gaynes:查看图片
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-10 14:00
林子大了什么鸟都有啊,我觉得我说的已经很客气了,阴阳谁呢
牛客62656195...:应该不是阴阳吧?你第一次注册的时候boss就说你是牛人
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务