Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- int main() {
- std::vector<std::string> input;
- std::string curr_read;
- int curr_cnt = 0;
- int last_cnt = 0;
- std::string curr_word;
- std::string last_word;
- std::cin >> curr_read;
- while (curr_read != ".") {
- input.push_back(curr_read);
- std::cin >> curr_read;
- }
- for (unsigned int i = 1; i < input.size(); i++) {
- if (input[i-1] == input[i]) {
- curr_word = input[i];
- curr_cnt++;
- } else {
- if (curr_cnt >= last_cnt) {
- last_cnt = ++curr_cnt;
- last_word = curr_word;
- }
- curr_cnt = 0;
- curr_word = " ";
- std::cout << last_word << last_cnt << std::endl;
- }
- }
- std::cout << "The word that got repeated the most times is: " << last_word << std::endl;
- std::cout << "Number of times: " << last_cnt << std::endl;
- std::cin.get();
- std::cin.get();
- return (0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement