Advertisement
Guest User

Untitled

a guest
Nov 24th, 2013
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <iomanip>
  4. #include <string>
  5. #include <sstream>
  6.  
  7. using namespace std;
  8.  
  9. const char CD1[] = "Book1.txt";
  10. const char CD2[] = "Book2.txt";
  11. const char RF[] = "Text.txt";
  12. const char RF2[] = "AnalyzeResults.txt";
  13.  
  14. const char CMAX = 100;
  15. const string skyr = " .,;:–!?()\t\n";
  16.  
  17. void Read(const char CD1[], string & eil, string & skyr);
  18. void Read2(const char CD2[], string & eil2, string & skyr);
  19. void Max(string & eil, string & skyr, int & ind, string max[]);
  20. bool Find(string f);
  21. void Less(string & eil);
  22. int Count(string eil);
  23.  
  24. int main(){
  25.     string eil, eil2;
  26.     string skyr = " .,;:–!?()\t\n";
  27.  
  28.     Read(CD1, eil, skyr);
  29.     Read2(CD2, eil2, skyr);
  30.  
  31.     system("pause");
  32.     return 0;
  33. }
  34. void Read(const char CD[], string & eil, string & skyr){
  35.     ifstream fd(CD1);
  36.     ofstream rf(RF);
  37.     ofstream rf2(RF2);
  38.     string max[10]; int ind = 0;
  39.     rf << string(35, '-') << "Data" << string(35, '-') << endl;
  40.  
  41.     while(!fd.eof()){
  42.         getline(fd, eil);
  43.         Max(eil, skyr, ind, max);
  44.         rf << eil << endl;
  45.         Less(eil);
  46.     }
  47.  
  48.     for(int j=0; j<ind; j++){
  49.         if(Find(max[j]) == true){
  50.         rf2 << max[j] << " " << max[j].length() << endl;
  51.         }
  52.     }
  53.     fd.close();
  54.     rf.close();
  55.     rf2.close();
  56. }
  57. void Read2(const char CD2[], string & eil2, string & skyr){
  58.     ifstream fd(CD2);
  59.     ofstream rf(RF, ios::app);
  60.     ofstream rf2(RF2, ios::app);
  61.     rf << endl << string(70, '-') << endl;
  62.     while(!fd.eof()){
  63.         getline(fd, eil2);
  64.         rf << eil2 << endl;
  65.         Less(eil2);
  66.     }
  67.     fd.close();
  68.     rf.close();
  69.     rf2.close();
  70. }
  71. void Less(string & eil){
  72.     for(int b=0; b<eil.length(); b++){
  73.         eil[b] = tolower(eil[b]);
  74.     }
  75. }
  76. void Max(string & eil, string & skyr, int & ind, string max[]){
  77.     string zodis;
  78.     int zpr = 0, zpb = 0;
  79.     while ((zpr = eil.find_first_not_of(skyr, zpb)) != string::npos){
  80.         zpb = eil.find_first_of(skyr, zpr);
  81.         zodis = eil.substr(zpr, zpb - zpr);
  82.         if(ind!=10){
  83.             max[ind++] = zodis;
  84.         }else{
  85.             for(int i=0; i<ind; i++){
  86.                 if(max[i].length() < zodis.length()){
  87.                     max[i] = zodis;
  88.                     break;
  89.                 }
  90.             }
  91.         }
  92.      }
  93. }
  94. bool Find(string f){
  95.     ifstream fd(CD2);
  96.     string eil;
  97.     while(!fd.eof()){
  98.         getline(fd, eil);
  99.         if(tolower(eil.find(f) != string::npos)){
  100.             return true;
  101.         }
  102.     }
  103.     fd.close();
  104.     return false;
  105. }
  106. int Count(string eil){
  107.     ifstream fd2(CD2);
  108.     string eil2;
  109.     int kiek = 0;
  110.     while(!fd2.eof()){
  111.         size_t startAt = 0;
  112.         getline(fd2, eil2);
  113.         while(true){
  114.             startAt = eil2.find(eil, startAt);
  115.             if(startAt != string::npos){
  116.                 startAt = startAt + eil.length();
  117.                 kiek++;
  118.                 continue;
  119.             }
  120.             break;
  121.         }
  122.     }
  123.     return kiek;
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement