zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    程序员必备的代码审查(Code Review)清单
    Laravel 在homestead 平台上命令
    Laravel5.5执行 npm run dev时报错,提示cross-env找不到(not found)的解决办法
    Laravel 的Artisan 命令学习
    github常见操作和常见错误!错误提示:fatal: remote origin already exists.
    Sublime如何设置背景透明
    jquery判断滚动条是否到底部
    mysql的数据恢复
    MySQL体系结构
    mysql-trigger-触发器
  • 原文地址:https://www.cnblogs.com/orchidzjl/p/6805900.html
Copyright © 2011-2022 走看看