当前位置: 首页 > news >正文

C++ //练习 11.4 扩展你的程序,忽略大小写和标点。例如,“example.“、“exmaple,“和”Example“应该递增相同的计数器。

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

练习 11.4 扩展你的程序,忽略大小写和标点。例如,“example.”、"exmaple,"和”Example"应该递增相同的计数器。

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

 

代码块

/*************************************************************************
	> File Name: ex11.4.cpp
	> Author: 
	> Mail: 
	> Created Time: Tue 02 Apr 2024 09:42:21 AM CST
 ************************************************************************/

#include<iostream>
#include<iomanip>
#include<cctype>
#include<string>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
    map<string, size_t> wordCount;
    set<string> unique = {".", ","};
    string word;
    
    cout<<"Enter words: ";
    while(cin>>word){
        transform(word.begin(), word.end(), word.begin(), ::tolower);
        if(ispunct(word[word.size()-1])){
            word.erase(word.size()-1);
        }
        ++wordCount[word];
        if(cin.get() == '\n'){
            break;
        }
    }

    cout<<"Word Count: "<<endl;
    for(const auto &w : wordCount){
        cout<<"Word: "<<setw(8)<<left<<w.first<<" Count: "<<w.second<<endl;
    }

    return 0;
}
运行结果显示如下

在这里插入图片描述

相关文章:

  • 使用node爬取视频网站里《龙珠》m3u8视频
  • 第十四届蓝桥杯(八题C++ 题目+代码+注解)
  • Python版【植物大战僵尸 +源码】
  • 非关系型数据库之Redis配置与优化
  • 【御控物联】JavaScript JSON结构转换(13):对象To数组——多层属性重组
  • 云计算面临的威胁
  • 【战略前沿】与中国达成生产协议后,飞行汽车即将起飞
  • GitHub git push超过100MB大文件失败(write error: Broken pipe)完美解决
  • 设计模式 —— 设计原则
  • http协议补充
  • TDK超高压陶瓷电容的国产替代---赫威斯电容HVC Capacitor
  • Linux: module: dump_pagetables: Unknown symbol init_top_pgt (err 0)
  • rust - 常用时间处理
  • React中使用antDesign框架
  • 超图打开不同格式的dem文件
  • Navicat 干货 | 通过检查约束确保 PostgreSQL 的数据完整性
  • Python位操作指南:从基础到应用
  • 【黑马头条】-day04自媒体文章审核-阿里云接口-敏感词分析DFA-图像识别OCR-异步调用MQ
  • 新能源充电桩站场AI视频智能分析烟火检测方案及技术特点分析
  • ctf题目
  • 营销型网站建设易网拓/查询收录
  • 西安网站建设gj/网站优化排名软件推广
  • 漂亮的企业网站源码/seo博客优化
  • 常州网站建设怎么样/建站公司排名
  • 网站策划书我与音乐/厦门seo排名外包
  • 学校网站建设计划书/地推拉新app推广接单平台免费