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;
}
相关推荐
进击的荆棘22 分钟前
递归、搜索与回溯——递归
算法·leetcode·递归
2301_822703201 小时前
鸿蒙Flutter第三方库FlutterUnit组件百科适配——具体示例还原演示1
算法·flutter·华为·harmonyos·鸿蒙
FuckPatience1 小时前
Visual Studio C# 项目中文件后缀简介
开发语言·c#
老四啊laosi8 小时前
[C++进阶] 24. 哈希表封装unordered_map && unordered_set
c++·哈希表·封装·unordered_map·unordered_set
2301_764441338 小时前
LISA时空跃迁分析,地理时空分析
数据结构·python·算法
东北洗浴王子讲AI8 小时前
GPT-5.4辅助算法设计与优化:从理论到实践的系统方法
人工智能·gpt·算法·chatgpt
014-code8 小时前
订单超时取消与库存回滚的完整实现(延迟任务 + 状态机)
java·开发语言
妙为8 小时前
银河麒麟V4下编译Qt5.12.12源码
c++·qt·国产化·osg3.6.5·osgearth3.2·银河麒麟v4
lly2024068 小时前
组合模式(Composite Pattern)
开发语言
Billlly8 小时前
ABC 453 个人题解
算法·题解·atcoder