Advertisement
Guest User

Untitled

a guest
Jun 18th, 2013
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4.  
  5. int main() {
  6.     std::vector<std::string> input;
  7.     std::string curr_read;
  8.     int curr_cnt = 0;
  9.     int last_cnt = 0;
  10.     std::string curr_word;
  11.     std::string last_word;
  12.    
  13.     std::cin >> curr_read;
  14.     while (curr_read != ".") {
  15.         input.push_back(curr_read);
  16.         std::cin >> curr_read;
  17.     }
  18.  
  19.     for (unsigned int i = 1; i < input.size(); i++) {
  20.         if (input[i-1] == input[i]) {
  21.             curr_word = input[i];
  22.             curr_cnt++;
  23.         } else {
  24.             if (curr_cnt >= last_cnt) {
  25.                 last_cnt = ++curr_cnt;
  26.                 last_word = curr_word;
  27.             }
  28.             curr_cnt = 0;
  29.             curr_word = " ";
  30.             std::cout << last_word << last_cnt << std::endl;
  31.         }
  32.     }
  33.  
  34.     std::cout << "The word that got repeated the most times is: " << last_word << std::endl;
  35.     std::cout << "Number of times: " << last_cnt << std::endl;
  36.  
  37.     std::cin.get();
  38.     std::cin.get();
  39.  
  40.     return (0);
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement