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}\)\s\d{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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧