forked from Mooophy/Cpp-Primer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex5_20.cpp
38 lines (32 loc) · 893 Bytes
/
ex5_20.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//!@Alan
//!
//! Exercise 5.20:
//! Write a program to read a sequence of strings from the standard
//! input until either the same word occurs twice in succession or
//! all the words have been read. Use a while loop to read the text
//! one word at a time. Use the break statement to terminate the loop
//! if a word occurs twice in succession. Print the word if it occurs
//! twice in succession, or else print a message saying that no word
//! was repeated.
//!
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
string current_str, previous_str;
cout<<"Please Enter:\n";
while(cin>>current_str)
{
if(current_str.compare(previous_str)==0)
{
break;
}
previous_str = current_str;
}
cout<<"The repeated word is "
<<previous_str
<<std::endl;
return 0;
}