forked from pezy/CppPrimer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex5_21.cpp
40 lines (35 loc) · 905 Bytes
/
ex5_21.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
39
40
//
// ex5_21.cpp
// Exercise 5.21
//
// Created by pezy on 11/9/14.
// Copyright (c) 2014 pezy. All rights reserved.
//
// @Brief Revise the program from the exercise in 5.5.1(p. 191)
// so that it looks only for duplicated words that start with an
// uppercase letter.
// @See Exercise 5.20
// @frank67 Rewrite using the 'continue' statement. See #250
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
#include <string>
using std::string;
int main()
{
string curr, prev;
bool no_twice = false;
while (cin >> curr) {
if (!isupper(curr[0]))
continue;
else if (prev == curr) {
cout << curr << " occurs twice in succession." << endl;
no_twice = true;
break;
}
else
prev = curr;
}
if (!no_twice) cout << "no word was repeated." << endl;
}