Skip to content

Commit

Permalink
Update ex5_14.cpp
Browse files Browse the repository at this point in the history
Adjust the format for code comparison.
  • Loading branch information
AlexHuang1734 committed Oct 31, 2014
1 parent 2414003 commit 5c01a82
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions ch05/ex5_14.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@

using std::cout; using std::cin; using std::endl; using std::string; using std::pair;

int main() {
int main()
{
pair<string, int> max_duplicated;
int count = 0;
for (string str, prestr; cin >> str; prestr = str)
{
if (str == prestr) { ++count;}
else count = 1;

pair<string, int> max_duplicated;
int count = 1;
for (string str, prestr; cin >> str; prestr = str)
{
if (str == prestr) { ++count;}
else count = 1;

if (count > max_duplicated.second + 1) {
max_duplicated = { prestr, count };
}
if (count > max_duplicated.second + 1) {
max_duplicated = { prestr, count };
}

if (max_duplicated.first.empty()) cout << "There's no duplicated string." << endl;
else cout << "the word " << max_duplicated.first << " occurred " << max_duplicated.second << " times. " << endl;

return 0;
}
}

if (max_duplicated.first.empty()) cout << "There's no duplicated string." << endl;
else cout << "the word " << max_duplicated.first << " occurred " << max_duplicated.second << " times. " << endl;

return 0;
}

0 comments on commit 5c01a82

Please sign in to comment.