阅读cin - 找到重复的单词 [英] reading cin - finding duplicate words

查看:98
本文介绍了阅读cin - 找到重复的单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个c ++类的新手...


我需要将标准输入读成几个字符串。然后确定

是否在SUCCESSION中使用了相同的单词(例如,这只猫猫是

真的意思。)。


然后计算并打印单词及其使用次数。因此,在上面的示例中使用

,它将打印出

继承中使用的单词以及它们被使用了多少次。例如,在上面的示例中,单词cat

被使用了2次。


我几乎坚持要运行什么样的测试来比较两个或

更多未知单词的相同性....


我们在课堂上并不是很远的字符串和向量...


感谢您的帮助。

解决方案

tm **** @ gmail.com 写道:

我是一个c ++类的新手...
我需要将标准输入读成几个字符串。然后确定是否在SUCCESSION中使用了相同的单词(例如,这只猫猫是真的意思。)。

然后计算并打印单词和多少次它被使用了。因此,使用上面的例子,它会打印出
继承中使用的单词以及它们被使用了多少次。例如,在上面的例子中,单词cat
被使用了2次。

我几乎坚持要进行什么样的测试来比较两个或更多未知的为了同一性而言......

我们在课堂上并不是很远的字符串和向量...

感谢您的帮助。




尝试使用std :: string。如果它不起作用,请向我们展示你所拥有的东西

远,我们可以给你一些指示。但是,我们不打算为你做一些家庭作业。


干杯! --M


所以这里是我的代码。在这一点上它并不是很有趣。


#include< iostream>

#include< string>

使用命名空间std;


int main()

{

//声明字符串

string s1;


//为单词

vector< string>声明一个向量v1;


//从stdinput获取输入到字符串,到向量

cout<< 请输入一个句子,然后按ENTER键: <<结束;


而(cin>> s1)

v.push_back(s1);


那么,我是否想在while / cin

阶段进行比较以找到重复项?


如果是这样,我不知道如何保持跟踪他们......我可以在和cin之间加上

语句吗?和v.pushback部分?


grrr。我甚至不知道要问的正确问题。


oops我忘了#include< vector>


I''m a newb in a c++ class...

I need to read the standard input into a couple strings. Then determine
whether or not the same word is used IN SUCCESSION (ex. this cat cat is
really mean.).

Then count and print the word and how many times it was used. So using
the above example, it would print out the words that were used in
succession and how many times they were used. For example, the word cat
was used 2 times inthe above example.

I''m pretty much stuck on what sort of test to run to compare two or
more unknown words for sameness....

we aren''t very far in the class past strings and vectors...

thanks for any help.

解决方案

tm****@gmail.com wrote:

I''m a newb in a c++ class...

I need to read the standard input into a couple strings. Then determine
whether or not the same word is used IN SUCCESSION (ex. this cat cat is
really mean.).

Then count and print the word and how many times it was used. So using
the above example, it would print out the words that were used in
succession and how many times they were used. For example, the word cat
was used 2 times inthe above example.

I''m pretty much stuck on what sort of test to run to compare two or
more unknown words for sameness....

we aren''t very far in the class past strings and vectors...

thanks for any help.



Try using std::string. If it doesn''t work, show us what you have so
far, and we can give you some pointers. We''re not going to do your
homework for you, however.

Cheers! --M


So here''s my code. It''s not very interesting at this point.

#include <iostream>
#include <string>
using namespace std;

int main()
{
//declaring strings
string s1;

//declare a vector for the words
vector<string> v1;

//aquiring input from stdinput, into string, into vector
cout << "Please enter a sentence and press ENTER: " << endl;

while (cin >> s1)
v.push_back(s1);

So, do I want to do comparisons to find duplicates at the while/cin
stage?

if so, i''m not sure how to keep track of them... can I tack on
statements between the "while cin" and the "v.pushback" part?

grrr. I dont even know the right questions to ask.


oops i forgot the #include <vector>


这篇关于阅读cin - 找到重复的单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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