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练习的更多相关文章

  1. bash 刷题leetcode

    题目一: 给定一个文本文件 file.txt,请只打印这个文件中的第十行. 示例: 假设 file.txt 有如下内容: Line 1 Line 2 Line 3 Line 4 Line 5 Line ...

  2. [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 ...

  3. 【leetcode】bash脚本练习

    [192]Word Frequency Write a bash script to calculate the frequency of each word in a text file words ...

  4. bash leetcode

    拓展:grep 193.  ref: https://blog.csdn.net/yanglingwell/article/details/82343407 Given a text file fil ...

  5. [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 ...

  6. [LeetCode] Tenth Line 第十行

    How would you print just the 10th line of a file? For example, assume that file.txt has the followin ...

  7. [LeetCode] Transpose File 转置文件

    Given a text file file.txt, transpose its content. You may assume that each row has the same number ...

  8. [LeetCode] Valid Phone Numbers 验证电话号码

    Given a text file file.txt that contains list of phone numbers (one per line), write a one liner bas ...

  9. [LeetCode] Word Frequency 单词频率

    Write a bash script to calculate the frequency of each word in a text file words.txt. For simplicity ...

随机推荐

  1. PSTAT 115 Homework4 课业解析

    PSTAT 115 Homework4 课业解析 题意: 蒙特卡洛采样之拒绝采样 解析: 给定一个概率分布p(z)=p~(z)/Zp,p~(z)已知,Zp为归一化常数,为未知数.对该分布进行拒绝采样, ...

  2. NetworkManager网络通讯_Example(一)

    ---恢复内容开始--- 用户手册,范例精讲. 用户手册上给出了一个简单的范例,并指出可以以此为基础进行相开发,再次对范例进行精讲.(NetworkManager对使用unity的轻量级游戏开发有很大 ...

  3. vue条件渲染2

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  4. fenby C语言 P15

    while(条件表达式){循环体} #include <stdio.h> int main(){ int i=1,sum=0; while(i<6) { sum=sum+i*3; i ...

  5. 谁说程序员不懂浪漫?用Python每天自动给女朋友免费发短信

    前言 之前发过一篇文章,用 Python 制作的给父母天气预报提醒的小工具天气变冷了,给父母制作一个天气提醒小助手,这篇文章我同步到博客上之后,有读者在评论区留言,对于部分微信没有网页版接口,导致无法 ...

  6. redis操作总结

    一.redis 终端操作命令: 1.redis-server.exe redis.windows.conf #指定配置文件启动 2.redis-cli #链接redis数据库 3.select 1 # ...

  7. TOMACT 各个版本集合

    http://archive.apache.org/dist/tomcat/ 再点击 bin 目录,找到想下载的即可

  8. Azure上MySQL的离线备份:将备份拷贝到Azure Blob上

    公司在Azure的Iaas虚拟机上部署有好几台MySQL数据库,至于没有选择Azure Database for MySQL,是因为预算有限(钱不够啊!说多了也是泪,坑的还是DBA自己).选择了Iaa ...

  9. C语言博客作业006

    问题 答案 这个作业属于那个课程 C语言程序设计1 这个作业要求在哪里 https://edu.cnblogs.com/campus/zswxy/CST2019-2/ 我在这个课程的目的是 学习并掌握 ...

  10. [考试反思]1105csp-s模拟测试102: 贪婪

    还是有点蠢... 多测没清空T3挂40...(只得了人口普查分20) 多测题要把样例复制粘两遍自测一下防止未清空出锅. 然而不算分... 其实到现在了算不算也不重要了吧... 而且其实T3只考虑最长路 ...