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 ...
随机推荐
- 使用jquery插件uploadfive、jcrop实现头像上传
1.html页面部分代码:(实现选着图片时,jcrop能够刷新图片) <script type="text/javascript"> $(function(){ $(& ...
- 一文读懂Java类加载机制
Java 类加载机制 Java 类加载机制详解. @pdai Java 类加载机制 类的生命周期 类的加载:查找并加载类的二进制数据 连接 验证:确保被加载的类的正确性 准备:为类的静态变量分配内存, ...
- swift 实现 iOS摇一摇
本博客包含了如何实现iOS摇一摇全步骤,包括了完整的代码. 先附上demo地址https://github.com/Liuyubao/LYBShake ,支持swift3.0+. 一.导包 项目主要使 ...
- 【PyTorch教程】P2. Python编辑器的选择、安装及配置
温馨提示:为了更好的教程体验,提供视频.阅读地址 Youtube: https://www.youtube.com/playlist?list=PLgAyVnrNJ96CqYdjZ8v9YjQvCBc ...
- LNMP下zabbix_server安装部署二
上一篇中搭建完成了zabbix的web端,但是虚拟机有点问题,所以转到笔记本上来写笔记本环境 server:192.168.112.9 agent:192.168.112.8 上一篇中完成了web ...
- 这次,我是如何监控服务器CPU和内存的
背景 在新项目A中,要结合业务做性能测试.对于做过N次性能测试的我,这次有些巧妇有难无米之炊的感觉.以往的项目,服务器都是部署在AWS或者阿里云,像这样的云服务器厂商是可以通过轻松配置各种Dashbo ...
- [考试反思]1102csp-s模拟测试98:苟活
好像没有什么粘文件得分的必要(本来就没多少分了也丢不了多少了) 而且从这次开始小绿框不代表首杀而代表手速了2333 其实我挺菜的,牛一个frepoen送掉100分才跟我并列%%%milkfun mik ...
- group:状压dp,轮廓线
神仙题.但是难得的傻孩子cbx没有喊题解,所以也就难得的自己想出来了一个如此神仙的题. 如果是自己想的,说它神仙是不是有点不合适啊..? 反正的确不好像.关键就在于这个标签.颓完标签就差不多会了. % ...
- 石头剪刀步(rps):dp,概率&期望
既然已经给std了,直接扔代码啦.代码注释还是不错哒. 因为我也有点懵,不明白的或有不同见解的一定要在评论区喷我啊! #include<bits/stdc++.h> using names ...
- [考试反思]0725NOIP模拟测试8
看清你是个什么东西了么? 现在看清了么?rank#15?垃圾玩意? 你什么也不是.你没有骄傲,偷懒的资格! 节节败退,永无止境,你想掉到什么样子? 你还在为了成功拿到送分的T1而沾沾自喜?只不过是勉强 ...