Skip to content

Commit

Permalink
Exercise 5.21 #250
Browse files Browse the repository at this point in the history
  • Loading branch information
frank67 authored and pezy committed May 26, 2015
1 parent 69fed8e commit d8a5f15
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions ch05/ex5_21.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,33 @@
// 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
// @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::cout; using std::cin; using std::endl; using std::string;
using std::string;

int main()
{
string read, tmp;
while ( cin >> read )
if (read == tmp && isupper(read[0])) break;
else tmp = read;

if (cin.eof()) cout << "no word was repeated." << endl;
else cout << read << " occurs twice in succession." << endl;
return 0;
string str_read, str_prev;

while ( cin >> str_read ) {
if ( !isupper(str_read[0]) )
continue;
else if ( str_prev == str_read ) {
cout << str_read << " occurs twice in succession." << endl;
str_read="";
break;
}
else str_prev = str_read;
}

if( !str_read.empty() )
cout << "no word was repeated." << endl;

return 0;
}

0 comments on commit d8a5f15

Please sign in to comment.