Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <iomanip>
- #include <string>
- #include <sstream>
- using namespace std;
- const char CD1[] = "Book1.txt";
- const char CD2[] = "Book2.txt";
- const char RF[] = "Text.txt";
- const char RF2[] = "AnalyzeResults.txt";
- const char CMAX = 100;
- const string skyr = " .,;:–!?()\t\n";
- void Read(const char CD1[], string & eil, string & skyr);
- void Read2(const char CD2[], string & eil2, string & skyr);
- void Max(string & eil, string & skyr, int & ind, string max[]);
- bool Find(string f);
- void Less(string & eil);
- int Count(string eil);
- int main(){
- string eil, eil2;
- string skyr = " .,;:–!?()\t\n";
- Read(CD1, eil, skyr);
- Read2(CD2, eil2, skyr);
- system("pause");
- return 0;
- }
- void Read(const char CD[], string & eil, string & skyr){
- ifstream fd(CD1);
- ofstream rf(RF);
- ofstream rf2(RF2);
- string max[10]; int ind = 0;
- rf << string(35, '-') << "Data" << string(35, '-') << endl;
- while(!fd.eof()){
- getline(fd, eil);
- Max(eil, skyr, ind, max);
- rf << eil << endl;
- Less(eil);
- }
- for(int j=0; j<ind; j++){
- if(Find(max[j]) == true){
- rf2 << max[j] << " " << max[j].length() << endl;
- }
- }
- fd.close();
- rf.close();
- rf2.close();
- }
- void Read2(const char CD2[], string & eil2, string & skyr){
- ifstream fd(CD2);
- ofstream rf(RF, ios::app);
- ofstream rf2(RF2, ios::app);
- rf << endl << string(70, '-') << endl;
- while(!fd.eof()){
- getline(fd, eil2);
- rf << eil2 << endl;
- Less(eil2);
- }
- fd.close();
- rf.close();
- rf2.close();
- }
- void Less(string & eil){
- for(int b=0; b<eil.length(); b++){
- eil[b] = tolower(eil[b]);
- }
- }
- void Max(string & eil, string & skyr, int & ind, string max[]){
- string zodis;
- int zpr = 0, zpb = 0;
- while ((zpr = eil.find_first_not_of(skyr, zpb)) != string::npos){
- zpb = eil.find_first_of(skyr, zpr);
- zodis = eil.substr(zpr, zpb - zpr);
- if(ind!=10){
- max[ind++] = zodis;
- }else{
- for(int i=0; i<ind; i++){
- if(max[i].length() < zodis.length()){
- max[i] = zodis;
- break;
- }
- }
- }
- }
- }
- bool Find(string f){
- ifstream fd(CD2);
- string eil;
- while(!fd.eof()){
- getline(fd, eil);
- if(tolower(eil.find(f) != string::npos)){
- return true;
- }
- }
- fd.close();
- return false;
- }
- int Count(string eil){
- ifstream fd2(CD2);
- string eil2;
- int kiek = 0;
- while(!fd2.eof()){
- size_t startAt = 0;
- getline(fd2, eil2);
- while(true){
- startAt = eil2.find(eil, startAt);
- if(startAt != string::npos){
- startAt = startAt + eil.length();
- kiek++;
- continue;
- }
- break;
- }
- }
- return kiek;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement