LeetCode Bash练习
195. Tenth Line
#!/bin/bash
i=
cat file.txt | while read line
do
#echo $line
if [ $i -eq ]
then echo $line
fi let i=i+
done
194. Transpose File
# Read from the file file.txt and print its transposed content to stdout.
#########################################################################
# File Name: .sh
# Author: atrp
# mail: scau_zjl@.com
# Created Time: Thu May :: AM EDT
#########################################################################
#!/bin/bash
i=
function getLen() {
num_column=$#
}
read line < file.txt
getLen $line
while [ -lt ]
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: .sh
# Author: atrp
# mail: scau_zjl@.com
# Created Time: Wed May :: PM EDT
#########################################################################
#!/bin/bash
grep -P "^\(\d{3}\)\s\d{3}-\d{4}$|^\d{3}-\d{3}-\d{4}$" file.txt
192. Word Frequency
###########################################################################
# File Name: .sh
# Author: atrp
# mail: scau_zjl@.com
# Created Time: Thu May :: AM EDT
#########################################################################
#!/bin/bash
declare -A map1=()
function calc() {
#echo $@
for i in $@
do
let map1["$i"]++
#echo ${map1["$i"]}
done
}
function out() {
times=
while [ $times -lt ${#map1[@]} ]
do
max=
id=
for i in ${!map1[@]}
do
if [ ${max} -lt ${map1[$i]} ]
then
max=${map1[$i]}
id=$i
fi
done
echo "${id} ${max}"
map1[${id}]= let times++
done
}
while read line
do
#echo $line
calc $line
done < words.txt out
LeetCode Bash练习的更多相关文章
- bash 刷题leetcode
题目一: 给定一个文本文件 file.txt,请只打印这个文件中的第十行. 示例: 假设 file.txt 有如下内容: Line 1 Line 2 Line 3 Line 4 Line 5 Line ...
- [LeetCode] 193. Valid Phone Numbers_Easy tag: Bash
Given a text file file.txt that contains list of phone numbers (one per line), write a one liner bas ...
- 【leetcode】bash脚本练习
[192]Word Frequency Write a bash script to calculate the frequency of each word in a text file words ...
- bash leetcode
拓展:grep 193. ref: https://blog.csdn.net/yanglingwell/article/details/82343407 Given a text file fil ...
- [LeetCode] 195. Tenth Line_Easy tag: Bash
Given a text file file.txt, print just the 10th line of the file. Example: Assume that file.txt has ...
- [LeetCode] Tenth Line 第十行
How would you print just the 10th line of a file? For example, assume that file.txt has the followin ...
- [LeetCode] Transpose File 转置文件
Given a text file file.txt, transpose its content. You may assume that each row has the same number ...
- [LeetCode] Valid Phone Numbers 验证电话号码
Given a text file file.txt that contains list of phone numbers (one per line), write a one liner bas ...
- [LeetCode] Word Frequency 单词频率
Write a bash script to calculate the frequency of each word in a text file words.txt. For simplicity ...
随机推荐
- vue-cli2、vue-cli3脚手架详细讲解
前言: vue脚手架指的是vue-cli它是vue官方提供的一个快速构建单页面(SPA)环境配置的工具,cli 就是(command-line-interface ) 命令行界面 .vue-cli是 ...
- netty源码解析(4.0)-26 ByteBuf内存池:PoolArena-PoolSubpage
PoolChunk用来分配大于或等于一个page的内存,如果需要小于一个page的内存,需要先从PoolChunk中分配一个page,然后再把一个page切割成多个子页-subpage,最后把内存以s ...
- jhipster入门
环境: 阿里云linux /////////////////////////////////////////////////////////////////////yum install java-1 ...
- 第3次作业-MOOC学习笔记:Python网络爬虫与信息提取
1.注册中国大学MOOC 2.选择北京理工大学嵩天老师的<Python网络爬虫与信息提取>MOOC课程 3.学习完成第0周至第4周的课程内容,并完成各周作业 4.提供图片或网站显示的学习进 ...
- travis-ci + php + casperjs 持续集成
.travis.yml 文件添加内容: sudo: required language: php php: - 5.5 before_script: - npm install -g casperjs ...
- 面对对象高阶+反射+魔法方法+单例(day22)
目录 昨日内容 组合 封装 property装饰器 多态 鸭子类型 今日内容 classmethod staticmethod 面对对象高级 isinstance issubclass 反射(重要) ...
- HDFS基本命令与Hadoop MapReduce程序的执行
一.HDFS基本命令 1.创建目录:-mkdir [jun@master ~]$ hadoop fs -mkdir /test [jun@master ~]$ hadoop fs -mkdir /te ...
- 四元数(Quaternion)
从应用角度说一下unity Quaternion,Quaternion是四元数,百度相关资料可能找到的都是一些大牛给你搞个矩阵云云,给你讲解四元数.在此只是从应用角度讲一讲.最简单理解四元数对应一个向 ...
- .NET进阶篇06-async异步、thread多线程1
知识需要不断积累.总结和沉淀,思考和写作是成长的催化剂 异步多线程挺大一块内容,既想拆开慢慢学,又想一股脑全倒出.纠结再三,还是拆开吃透,也不至于篇幅过长,劝退许多人 本篇先做一个概述,列明一些基本概 ...
- android内嵌H5页(webview)如何定位
一.切换至webview后再定位元素 (1)获取页面上下文 contexts = driver.contexts (2)切换至webview driver.switch_to.context(cont ...