Created
December 26, 2012 01:47
-
-
Save id-0x76adf1/4377108 to your computer and use it in GitHub Desktop.
Keep track of the largest number of times a single repetition occurs and which word is repeated.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <string> | |
| int main(int arc, char* argv[]) | |
| { | |
| int max_count = 0; | |
| std::string max_count_word; | |
| int count = 0; | |
| std::string prev_word; | |
| std::string curr_word; | |
| std::cin >> curr_word; | |
| prev_word = curr_word; | |
| ++count; | |
| while (std::cin >> curr_word) | |
| { | |
| if (curr_word == prev_word) | |
| { | |
| ++count; | |
| } | |
| else | |
| { | |
| if (count > max_count) | |
| { | |
| max_count = count; | |
| max_count_word = prev_word; | |
| prev_word = curr_word; | |
| } | |
| } | |
| } | |
| if (max_count > 1) | |
| { | |
| std::cout << max_count_word << " ocurrs " << max_count << " times" << std::endl; | |
| } | |
| else | |
| { | |
| std::cout << "no word was repeated" << std::endl; | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment