C ++中的唯一字数帮助? [英] Unique word count in C++ help?

查看:88
本文介绍了C ++中的唯一字数帮助?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做一个可以计算唯一字词的函数。例如:

I would like to do a function which can count the unique words. For example:

我喜欢编程有用的东西,我喜欢吃,现在吃冰激凌。

"I like to program something useful. And I like to eat. Eat ice-cream now."

在这种情况下,每个唯一字:

In this case, each unique words:

I occurs 2
like occurs 2
...

稍后我将忽略此情况。请帮助

I will ignore the case later on. Please help

编辑:

我写完了函数。它工作完美。感谢所有的帮助。非常感谢。

I have finished write the functions. It works perfectly. Thanks for all the help. Very much appreciated.

推荐答案

听起来你想使用 std :: map ,其中包含一个键字符串和数据int。

Sounds like you want to use an std::map with a key string and data of int.

如果地图中不存在的项目已经添加了int值为1.如果该项目在地图中已经存在,只需将1添加到其关联值。

If an item doesn't exist in the map already you add it with an int value of 1. If the item does exist in the map already you simply add 1 to its associated value.

这篇关于C ++中的唯一字数帮助?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆