Scala案例:全文单词统计

ops/2024/11/24 2:00:37/

 2.txt内容如下

Thank you very much.Well I want to thank you all very much this is great, these are our friends, we have thousands of friends in this incredible movement.This was a movement like no nobody's ever seen before, and frankly this was I believe the greatest political movement of all time.There's never been anything like this in this country, and maybe beyond and now it's going to reach a new level of importance, because we're going to help our country heal, we're going to help our country heal, we have a country that needs help and it needs help very badly, we're going to fix our borders, we're going to fix everything about our country, and we made history for a reason tonight, and the reason is going to be just that.We overcame obstacles that nobody thought possible, and it is now clear that we've achieved the most incredible political thing, look what happened is this crazy?But it's a political victory that our country has never seen before nothing like this.I want to thank the American people for the extraordinary honor of being elected your 47th president and your 45th president.And every citizen I will fight for you for your family and your future every single s day.I will be fighting for you, and with every breath in my body.I will not rest until we have delivered the strong safe and prosperous America that our children deserve, and that you deserve.This will truly be the Golden Age of America that's what we have to have.This is a magnificent victory for the American people that will allow us to make America great again.And in addition to having won the battleground states of North Carolina, I love these places.Georgia Pennsylvania and Wisconsin we are now winning in Michigan Arizona Nevada and Alaska, which would result in US carrying at least 315 electoral votes, but as much easier doing what the networks did or whoever called it, because there was no other path.There was no other path to victory.We also have won the popular vote that was great. Thank you very much thank you.Winning the popular vote was very nice very nice, I will tell you.It's a great a great feeling of love we have a great feeling of love in this very large room with unbelievable people, standing by my side.These people have been incredible they've made the journey with me and we're going to make you very happy, we're going to make you very proud of your vote.I hope that you're going to be looking back someday, and say that was one of the truly important moments of my life, when I voted for this group of people beyond the president, this group of great people.America has given us an unprecedented and powerful mandate.We have taken back control of the Senate. That's great And the Senate races in Montana Nevada Texas Ohio Michigan Wisconsin, the great Commonwealth of Pennsylvania we all won by the MAGA movement they helped so much.And in those cases every one of them we worked with the Senators.They were tough races and I mean the number of victories in the Senate was absolutely incredible, and we did tell rallies we did tell rallies, with each one of them, and sometimes we did two or three for and it was amazing to look at all of those victories, nobody expected that nobody.So I just wanted to thank you very much for that and we have.You have some great senators and some great new senators, and it also looks like we'll be keeping control of the House of Representatives, and I want to thank Mike Johnson, I think he's doing a terrific job terrific job.I want to also thank my beautiful wife Melania first lady, who has the number one bestselling book in the country can you believe that?Now she's done a great job, works very hard, works very hard to help people, so I just want to thank her, but I want to thank my whole family, my amazing children and they are amazing children.Now we all thank our children are, everybody here thinks their children are amazing but that's a good thing when you think they are, but Don, Eric, Ivanka, Tiffany, Baron, Lura, Jared, Kimberly, Michael, thank you all what a help.

import java.io.PrintWriter
import scala.collection.mutable
import scala.io.Source
object t20 {def main(args: Array[String]): Unit = {//1.读入文件val content=Source.fromFile("C:\\Users\\Administrator\\Desktop\\2.txt").mkStringprintln(content)//2.拆分字符串 --> 单词数组
//    val rs=content.split(" ")   //正则表达式
//    \\正则
//    W:表示非字符(,空格 ?...)
//    W+:多个非字符val rs=content.split("\\W+")println("-"*40)rs.foreach(println)//3.统计出现的频率val wordsMap=mutable.Map[String,Int]()rs.foreach(w=>{val word=w.toLowerCase()//全小写//是否出现if(wordsMap.contains(word)){wordsMap(word)+=1}else{wordsMap(word)=1}})//4.根据出现的次数从高到低排序// Map不能直接排序,需要转成有序的集合val orderlist=wordsMap.toList.sortWith((a,b)=>a._2>b._2)//5.保存结果,涉及写入文件val writer=new PrintWriter("output.txt")for(e<-orderlist){println(e._1,e._2)//打印到屏幕writer.println(s"${e._1} : ${e._2}次")}writer.close()}
}

 


http://www.ppmy.cn/ops/135844.html

相关文章

ZYNQ-7020嵌入式系统学习笔记(1)——使用ARM核配置UART发送Helloworld

本工程实现调用ZYNQ-7000的内部ARM处理器&#xff0c;通过UART给电脑发送字符串。 硬件&#xff1a;正点原子领航者-7020 开发平台&#xff1a;Vivado 2018、 SDK 1 Vivado部分操作 1.1 新建工程 设置工程名&#xff0c;选择芯片型号。 1.2 添加和配置PS IP 点击IP INTEGR…

开源 - Ideal库 - 枚举扩展设计思路及实现难点(三)

今天想和大家分享关于枚举扩展设计思路和在实现过程中遇到的难点。 01、设计思路 设计思路说起来其实也很简单&#xff0c;就是通过枚举相关信息&#xff1a;枚举值、枚举名、枚举描述、枚举项、枚举类型&#xff0c;进行各种转换&#xff0c;通过一个信息获取其他信息。比如通…

fio检测硬盘的读写是都正常

有时候发现访问磁盘上文件很慢,但是不知道到底是不是硬盘的问题,此时可以使用该工具进行检测以方便排查问题 一、下载 https://github.com/axboe/fio/releases 注:(1)官网地址无法下载(https://bsdio.com/fio/、https://brick.kernel.dk/snaps/) 二、安装 1、Windo…

服务器被隔离导致无法登录

现象描述 云服务器可能会因安全违规&#xff08;内容或行为违规&#xff09;或因 DDoS 攻击被封堵隔离&#xff0c;被隔离的云服务器在控制台显示为 “BANNING” 状态。 云服务器被隔离可能由于该台服务器违反了当前法律法规的要求。您可以通过以下方式查看该台服务器是否处于…

Java List 集合

怀旧网个人博客网站地址&#xff1a;怀旧网&#xff0c;博客详情&#xff1a;Java List 集合 List 集合的特点 List 集合的特有方法 因为List是Collection 的子类&#xff0c;所以List也直接继承了所有的Collection 的方法。 List 集合方法代码测试 创建集合对象 因为List也…

【数据结构】【线性表】栈的顺序存储实现(附C语言源码)

顺序栈 栈的顺序存储实现顺序栈的定义顺序栈的初始化进栈出栈读栈顶元素共享栈 栈的顺序存储实现 在之前的内容中我们讲过&#xff0c;栈也是线性表的一种&#xff0c;它和顺序表以及链表的区别不在存储结构上&#xff0c;而是在删除和插入的操作上&#xff0c;栈只允许在其一…

PostgreSQL 性能优化全方位指南:深度提升数据库效率

PostgreSQL 性能优化全方位指南&#xff1a;深度提升数据库效率 别忘了请点个赞收藏关注支持一下博主喵&#xff01;&#xff01;&#xff01; 在现代互联网应用中&#xff0c;数据库性能优化是系统优化中至关重要的一环&#xff0c;尤其对于数据密集型和高并发的应用而言&am…

摄像机ISP和DSP的区别?

影像处理器是现代数字相机、手机等电子设备中极其重要的一部分&#xff0c;它能够对传感器采集的图像进行多种操作&#xff0c;从而得到更高质量的图像。常见的两种影像处理芯片有ISP&#xff08;Image Signal Processor&#xff09;和DSP&#xff08;Digital Signal Processor…