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;
}
相关推荐
zd8451015001 天前
[LWIP] LWIP热插拔功能 问题调试
开发语言·php
趁月色小酌***1 天前
JAVA 知识点总结4
java·开发语言
C雨后彩虹1 天前
ConcurrentHashMap 源码逐行拆解:put/get 方法的并发安全执行流程
java·算法·哈希算法·集合·hashmap
wuguan_1 天前
C#:try和catch(保护程序不崩溃)
开发语言·c#·try catch
无限进步_1 天前
C++ STL list容器深度解析与模拟实现
开发语言·数据结构·c++·windows·git·list·visual studio
子夜江寒1 天前
SVM、K-means与DBSCAN 算法简介
算法·支持向量机·kmeans
黑贝是条狗1 天前
Delphi TCP通信帧设计,类型Websocket通信帧
开发语言·c#
黎雁·泠崖1 天前
C 语言动态内存管理高阶:柔性数组特性 + 程序内存区域划分全解
c语言·开发语言·柔性数组
趣知岛1 天前
初识Java
java·开发语言
步菲1 天前
springboot canche 无法避免Null key错误, Null key returned for cache operation
java·开发语言·spring boot