C++ //练习 14.39 修改上一题的程序令其报告长度在1至9之间的单词有多少个、长度在10以上的单词又有多少个。

C++ Primer(第5版) 练习 14.39

练习 14.39 修改上一题的程序令其报告长度在1至9之间的单词有多少个、长度在10以上的单词又有多少个。

环境:Linux Ubuntu(云服务器)
工具:vim

代码块

cpp 复制代码
class Check{
	public:
	Check(int s = 0): sz(s){}
	bool operator()(const string& s){
		return s.size() == sz ? true : false;
	}

	private:
	size_t sz;
};

int main(){
	vector<string> str;
	string s;
	while(cin>>s){
		str.push_back(s);
		if(cin.get() == '\n'){
			break;
		}
	}
	int count = 0;
	for(int i = 1; i < 10; i++){
		count += count_if(str.begin(), str.end(), Check(i));
	}
	cout<<"Length(1~9) words: "<<count<<endl;
	cout<<"Length(>=10) words: "<<str.size() - count<<endl;

	return 0;
}
相关推荐
思茂信息19 小时前
CST软件对Customer Success OPPO手机电源适配器EMC仿真
开发语言·嵌入式硬件·matlab·3d·智能手机·cst
LDG_AGI19 小时前
【推荐系统】深度学习训练框架(八):PyTorch分布式采样器DistributedSampler原理详解
人工智能·pytorch·分布式·深度学习·算法·机器学习·推荐算法
缺点内向20 小时前
如何在 C# 中将 Excel 工作表拆分为多个窗格
开发语言·c#·.net·excel
少废话h21 小时前
解决Flink中ApacheCommonsCLI版本冲突
开发语言·python·pycharm
Nebula_g21 小时前
C语言应用实例:背包DP1(Bone Collector、Piggy-Bank、珍惜现在,感恩生活)
算法
天命码喽c21 小时前
GraphRAG-2.7.0整合Milvus-2.5.1
开发语言·python·milvus·graphrag
后端小张21 小时前
【JAVA进阶】Spring Boot 核心知识点之自动配置:原理与实战
java·开发语言·spring boot·后端·spring·spring cloud·自动配置
roman_日积跬步-终至千里21 小时前
【模式识别与机器学习(5)】主要算法与技术(中篇:概率统计与回归方法)之逻辑回归(Logistic Regression)
算法·机器学习·回归
Mr_Xuhhh1 天前
YAML相关
开发语言·python
阿巴~阿巴~1 天前
JsonCpp:C++ JSON处理利器
linux·网络·c++·json·tcp·序列化和反序列化