按字典序统计给定文字段单词出现次数

这篇博客展示了如何使用C++和C#编程语言,按字典顺序统计一段文字中各个单词出现的次数。文中包含代码示例及测试结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

按字典序统计下面这段文字中单词出现的次数

代码:


#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
bool compare(char* a,char* b)//自定义规则排序
{
   
if(strcmp(a,b)==-1) //a<b
 return 1;
if((strcmp(a,b)==1)||(strcmp(a,b)==0)) //a>=b
 return 0; }
void main()
{
   
vector<char*> vec;
char* p="It was the best of times, and it was the worst of times. It was the age of wisdom, and it was the age of foolishness. It was the epoch of belief, and it was the epoch of incredulity. It was the season of light, and it was the season of darkness. It was the spring of hope, and it was the winter of despair. We had everything before us, and we had nothing before us. We were all going direct to Heaven, and we were all going direct the other way. In short, the period was so far like the present period. That some of its noisiest authorities insisted on its being received, for good or for evil, in the superlative degree of comparison only."
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值