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 ...
随机推荐
- BeetleX服务网关之服务发现与泛域名路由
在新版本的服务网关中提供了服务发现和泛域名路由解决功能,服务发现可以在无须配置的情况下实现服务自动注册到网关中解脱对服务配置的繁琐工作:而泛域名路由则可以针对不同的域名制定不同的负载规则. 使用con ...
- JAVA aio简单使用
使用aio,实现客户端和服务器 对一个数进行轮流累加 //服务器端 public class Server { private static ExecutorService executorServi ...
- 使用SQLserver Management Studio连接VS2012自带数据库
下载 Microsoft® SQL Server® 2008 Management Studio Express http://www.microsoft.com/zh-CN/download/det ...
- 数据结构(四十)平衡二叉树(AVL树)
一.平衡二叉树的定义 平衡二叉树(Self-Balancing Binary Search Tree或Height-Balanced Binary Search Tree),是一种二叉排序树,其中每一 ...
- SpringCloud之Nacos服务注册(十八)
一 服务提供配置 pom.xml <dependency> <groupId>org.springframework.boot</groupId> <arti ...
- windows 10 环境下 使用Anaconda搭建 TensorFlow 环境
##大致步骤 1 安装Anaconda 2 在Anaconda中建立虚拟TensorFlow的虚拟环境 建立虚拟环境的命令是 conda create -n tensorflow python=3. ...
- (JavaScript) 时间转为几天前、几小时前、几分钟前
// 时间戳转多少分钟之前 getDateDiff(dateTimeStamp) { // 时间字符串转时间戳 var timestamp = new Date(dateTimeStamp).getT ...
- CMMS系统中的物联监测
有条件的设备物联后,可时实查看设备运行状态,如发现异常,可提前干预.
- Django学习day3——Django的简单使用
开始一个项目 切换到django的虚拟环境中 执行: django-admin startproject mysite 创建第一个django项目mysite django生成的目录如下: E:. └ ...
- [考试反思]0803NOIP模拟测试12:偿还
嗯,rank5.没什么可评价的,高不算高低不算低. 一套好题,被我浪费了. 离上面280的大神差的有点远. 分机房的绝响就要来临. 越来越感觉自己变菜了,整体的能力水平在下滑. 说的不只是考试,包括平 ...