ios::sync_with_stdio(false); locale loc; if(os=='W') loc.global(locale("")); else loc.global(locale("en_US.UTF-8")); wcout.imbue(loc); if(os=='W') system("dir /b *.txt > files.dat"); else system("ls *.txt > files.dat"); vector<string> FileList; string file; ifstream fp("files.dat"); fp>>file; while(!fp.eof()) { FileList.push_back(file); fp>>file; } fp.close(); int NofFile=FileList.size(); int choice, slot, i, j, c; pair<string,int> SortedFiles[NofFile]; wstring str; string s; cout<<"\n\nChoose a method : \n"; cout<<"1. Hash tables\n"; cout<<"2. Tries\n"; cout<<"3. Boyer Moore Algorithm\n"; cout<<"Enter choice : "; cin>>choice; list<string> H[m][NofFile]; list<string> B[NofFile]; wifstream FP; switch(choice) { case 1: for(int f=0;f<NofFile;f++) { char* CurrFile=&FileList[f][0]; FP.open(CurrFile); FP.imbue(loc); FP>>str; while(!FP.eof()) { string s( str.begin(), str.end() ); i=0; j=s.length(); if(!s.empty()) { while(!isalnum(s[i])) i++; while(!isalnum(s[j])) j--; } if(j>=i) { s=s.substr(i,j-i+1); transform(s.begin(), s.end(), s.begin(), ::tolower); slot=h(s); H[slot][f].push_front(s); } FP>>str; } FP.close(); } cout<<"Enter a word to search : "; cin>>s; transform(s.begin(), s.end(), s.begin(), ::tolower); slot=h(s); for(int f=0;f<NofFile;f++) { SortedFiles[f].first=FileList[f]; SortedFiles[f].second=count(H[slot][f].begin(),H[slot][f].end(),s); } break;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)