Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- #include <algorithm> // std::remove_if
- #include <fstream>
- using namespace std;
- bool checkExists(vector<string> v, string key)
- {
- bool returnString=false;
- for (int i=0; i<v.size(); i++)
- {
- if (v[i]==key)
- returnString=true;
- }
- return returnString;
- }
- void cleanup(string &s)
- {
- s.erase(remove_if(s.begin(), s.end(), ::ispunct), s.end());
- }
- string downSize(string &line)
- {
- char x;
- for(char& c : line)
- {
- x = c;
- if (c > 64 && c < 90)
- {
- c += 32;
- }
- replace(line.begin(), line.end(), x, c);
- }
- return line;
- }
- bool isValid(string s)
- {
- for (int i = 0, j = 1; j < s.length(); i++, j++)
- {
- if (toupper(s[i]) >= 'A' && toupper(s[i]) < 'N')
- {
- if (toupper(s[j]) < 'N')
- return false;
- }
- else if (toupper(s[i]) >= 'N')
- {
- if (toupper(s[j]) >= 'N')
- return false;
- }
- }
- return true;
- }
- int whichList(string halfabet)
- {
- int returnInt = -1;
- //if starts with a-m and ends with a-m
- if (halfabet[0]>= 'a' && halfabet[0] <'n')
- if (halfabet[halfabet.length()-1]>= 'a' && halfabet[halfabet.length()-1] < 'n')
- returnInt=0;
- //if starts with a-m and ends with m-z
- if (halfabet[0]>= 'a' && halfabet[0] <'n')
- if (halfabet[halfabet.length()-1] >= 'n')
- returnInt=1;
- //if starts with a-m and ends with m-z
- if (halfabet[0]>= 'n')
- if (halfabet[halfabet.length()-1]>= 'a' && halfabet[halfabet.length()-1] < 'n')
- returnInt=2;
- //if starts with m-z and ends with m-z
- if (halfabet[0] >= 'n')
- if (halfabet[halfabet.length()-1] >= 'n')
- returnInt=3;
- //return -
- //0 = FF
- //1 = FL
- //2 = LF
- //3 = LL
- return returnInt;
- }
- int main()
- {
- vector<string> FF;
- vector<string> FL;
- vector<string> LF;
- vector<string> LL;
- ifstream fin;
- fin.open("Book.txt");
- string word;
- //if file is open
- if(fin.is_open())
- {
- //while file has text
- while (!fin.eof())
- {
- fin>>word;
- downSize(word);
- //clean it up for punctuation
- cleanup(word);
- bool halfabetCheck = isValid(word);
- if (halfabetCheck)
- {
- //find list
- //if 0..1..2...3 push back etc
- int list = whichList(word);
- if (list == 0)
- {
- //check if exists already
- if (!checkExists(FF,word))
- {
- FF.push_back(word);
- }
- }
- if (list == 1)
- {
- //check if exists already
- if (!checkExists(FL,word))
- {
- FL.push_back(word);
- }
- }
- if (list == 2)
- {
- //check if exists already
- if (!checkExists(LF,word))
- {
- LF.push_back(word);
- }
- }
- if (list == 3)
- {
- //check if exists already
- if (!checkExists(LL,word))
- {
- LL.push_back(word);
- }
- }
- }
- ofstream foutFF;
- foutFF.open("FF.txt");
- ofstream foutFL;
- foutFL.open("FL.txt");
- ofstream foutLF;
- foutLF.open("LF.txt");
- ofstream foutLL;
- foutLL.open("LL.txt");
- for (int i=0; i<FF.size(); i++)
- {
- foutFF<<FF[i]<<endl;
- }
- for (int i=0; i<FL.size(); i++)
- {
- foutFL<<FL[i]<<endl;
- }
- for (int i=0; i<LF.size(); i++)
- {
- foutLF<<LF[i]<<endl;
- }
- for (int i=0; i<LL.size(); i++)
- {
- foutLL<<LL[i]<<endl;
- }
- }
- }
- fin.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement