1/*
 2編寫一個小程序,從標準輸入讀入一系列 string 對象,尋找連續重復出現的單詞。
 3程序應該找出滿足以下條件的單詞的輸入位置:該單詞的后面緊跟著再次出現自己本身。
 4跟蹤重復次數最多的單詞及其重復次數。輸出重復次數的最大值,若沒有單詞重復則輸出說明信息。
 5例如,如果輸入是:
 6
 7     how, now now now brown cow cow
 8
 9則輸出應表明“now”這個單詞出現了三次。
10
11*/

12#include <iostream>
13#include <string>
14
15using namespace std;
16
17int main()
18{
19    string bufString = "",word = "",Aword("");
20    int count1 = 0,count2 = 0;
21    while(getline(cin,bufString))
22    {
23        if(bufString == word)
24        {
25            count1++;
26            word = bufString;
27        }

28        else
29        {
30            
31            if(count1>count2)
32            {
33               count2 = count1;
34               Aword = word;
35            }

36            word = bufString;
37            count1 = 1;
38        }

39    }

40    cout << "Aword:" << Aword << "  times:" << count2 << endl;
41    return 0;
42}