Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <vector>
  5. #include <algorithm>
  6. #include <string>
  7.  
  8. using namespace std;
  9.  
  10. const int LENGTH = 1000;
  11.  
  12. void readData(string *words)
  13. {
  14.     string tmp;
  15.     ifstream file;
  16.     file.open("NAPIS.TXT");
  17.  
  18.     for (int i = 0; i < LENGTH; i++) {
  19.         file >> words[i];
  20.     }
  21.  
  22.     file.close();
  23. }
  24.  
  25. void findAllRepeatingWords(string *words)
  26. {
  27.     string repeated;
  28.  
  29.     int i = 0;
  30.     while (i < LENGTH) {
  31.         repeated = "";
  32.         while (words[i++].compare(words[i]) == 0) {
  33.             repeated = words[i];
  34.         }
  35.         if (!repeated.empty()) {
  36.             cout << repeated << endl;
  37.         }
  38.     }
  39. }
  40.  
  41. int main()
  42. {
  43.     string words[LENGTH];
  44.     readData(words);
  45.     sort(words, words + LENGTH);
  46.     findAllRepeatingWords(words);
  47.  
  48.     return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement