C++ 编程的问题,麻烦各位帮我编一下,谢谢!!!
来源:百度知道 编辑:UC知道 时间:2024/05/29 18:00:01
从标准输入读入一系列string对象,寻找重复出现的单词。程序应该找出满足以下条件的单词的输入位置:该单词后面紧跟着再次出现自己本身。跟踪重复次数最多的单词及重复次数。输出重复次数的最大值,若没有单词重复则输出说明信息。例如,如果输入的是:
how now now now brown cow cow
则输出应表明“now”这个单词出现了3次。
how now now now brown cow cow
则输出应表明“now”这个单词出现了3次。
#include <iostream>
#include <sstream>
using namespace std;
void main( ) {
string line;
getline( cin, line );
stringstream ss( line );
string previousWord,
currentWord,
wordOfMaxCR; // CR == Consecutive Repetition
int maxCR = 0,
currentCR = 0;
while ( ss >> currentWord ) {
if ( previousWord == currentWord )
currentCR++;
el