• LeetCode Bash练习


    195. Tenth Line

    #!/bin/bash
    i=0
    cat file.txt | while read line
    do
        #echo $line
        if [ $i -eq 9 ]
            then echo $line
        fi
        
        let i=i+1
    done
        

     194. Transpose File

    # Read from the file file.txt and print its transposed content to stdout.
    #########################################################################
    # File Name: 194.sh
    # Author: atrp
    # mail: scau_zjl@163.com
    # Created Time: Thu 04 May 2017 09:02:39 AM EDT
    #########################################################################
    #!/bin/bash
    i=1
    function getLen() {
        num_column=$#
    }
    read line < file.txt
    getLen $line
    while [ 0 -lt 1 ]
    do
        column=`cut -d' ' -f$i ./file.txt`
        echo ${column}
        if [ $i -eq ${num_column} ]
        then
            break
        fi
        let i++
    done

    193. Valid Phone Numbers

    #########################################################################
    # File Name: 193.sh
    # Author: atrp
    # mail: scau_zjl@163.com
    # Created Time: Wed 03 May 2017 11:08:51 PM EDT
    #########################################################################
    #!/bin/bash
    grep -P "^(d{3})sd{3}-d{4}$|^d{3}-d{3}-d{4}$" file.txt

    192. Word Frequency

    ###########################################################################
    # File Name: 192.sh
    # Author: atrp
    # mail: scau_zjl@163.com
    # Created Time: Thu 04 May 2017 06:38:21 AM EDT
    #########################################################################
    #!/bin/bash
    declare -A map1=()
    function calc() {
        #echo $@
        for i in $@
        do 
            let map1["$i"]++
            #echo ${map1["$i"]}
        done
    }
    function out() {
        times=0
        while [ $times -lt ${#map1[@]} ]
        do
            max=0
            id=0
            for i in ${!map1[@]}
            do
                if [ ${max} -lt ${map1[$i]} ]
                then
                    max=${map1[$i]}
                    id=$i
                fi
            done
            echo "${id} ${max}"
            map1[${id}]=0
    
            let times++
        done
    }
    while read line
    do
        #echo $line
        calc $line
    done < words.txt
    
    out
  • 相关阅读:
    PROXY SERVER 代理服务器
    微信小程序跳转navigateTo与redirectTo
    在C#中实现类似位域的操作
    用WPF的Dock控件重写了原来的那个正则表达式测试工具
    获取文件夹所占空间的大小
    索尼正式公布新掌机PSP2——NGP
    一个打印螺旋数的程序
    在C#中实现BigEndian的数字
    通过程序关闭显示器
    索爱的Xperia arc太漂亮了
  • 原文地址:https://www.cnblogs.com/orchidzjl/p/6805900.html
Copyright © 2020-2023  润新知