1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
|
#include <iostream>
#include <sstream>
#include <string>
#include <stdio.h>
#include <locale>
#include <stdlib.h>
using namespace std;
bool isIgnored(string wordCheck, string ignoredWords[], int ignoreCount) {
for (int loop=0; loop<ignoreCount; loop++) {
cout << "loop: " << loop << endl;
if(wordCheck==ignoredWords[loop]) {
return true;
}
}
return false;
}
struct storeByKeyWord {
string keyword;
string entireTitle;
storeByKeyWord* next;
};
string word, newCapWord, newCapPhrase;
int ignoreCount=0;
int numTitles=0;
bool spaceBefore;
int titleLength;
bool wordUnique;
int wordBegCur, wordLeng, curCursor;
int main()
{
storeByKeyWord *head=NULL, *curr=NULL, *tail=NULL, *findPlace=NULL, *findPlaceLag=NULL;
string* titles=new string[200];
string* wordsIgnore=new string[50];
while(1) {
cin >> word;
if (word=="::") {
break;
}
wordsIgnore[ignoreCount]=word;
ignoreCount++;
}
while (getline(cin, word, '\n')) {
if (!cin||word=="END") {
break;
}
if (word=="") continue;
titles[numTitles]=word;
titleLength=word.length();
for (int looptoLower=0; looptoLower<titleLength; looptoLower++) {
//cout << "looptoLower, char: " << looptoLower << ", " <<
//word[looptoLower]<< endl;
word[looptoLower]=char(tolower(word[looptoLower]));
//cout << "char after" << word[looptoLower] << endl;
}
titles[numTitles]=word;
numTitles++;
}
cout << "did END" << endl;
for (int loopFindKeywords=0; loopFindKeywords<numTitles; loopFindKeywords++) {
cout << "Working on title #" << loopFindKeywords << endl;
cout << titles[loopFindKeywords] << endl;
wordBegCur=0; wordLeng=0; curCursor=0;
titleLength=(titles[loopFindKeywords]).length();
newCapPhrase=titles[loopFindKeywords];
cout << "titleLength " << titleLength << endl;
while (curCursor<titleLength-1) {
curCursor=wordBegCur;
wordLeng=0;
cout << "In string, searching for words" << endl;
while ((newCapPhrase[curCursor]!=' ')&&(curCursor<=titleLength-1)) {
wordLeng++;
curCursor++;
}
cout << "Word Beg, Word Length, curCursor: " << wordBegCur << ", " <<
wordLeng << ", " << curCursor << endl;
newCapWord=newCapPhrase.substr(wordBegCur,wordBegCur+wordLeng);
cout << newCapWord << endl;
if (!isIgnored(newCapWord, wordsIgnore, ignoreCount)) {
cout << "Word detected as not ignored" << endl;
for (int loopCap=0; loopCap<wordLeng; loopCap++) {
newCapWord[loopCap]=char(toupper(newCapWord[loopCap]));
}
cout << "finished capitalisation" << endl;
cout << newCapWord << endl;
newCapPhrase.replace(wordBegCur, wordBegCur+wordLeng, newCapWord);
cout << "finished replacing" << endl;
cout << newCapPhrase << endl;
curr=(storeByKeyWord*)malloc(sizeof(storeByKeyWord));
cout << "created new storeByKeyWord" << endl;
if (head==NULL) {
head=curr;
cout << "set head to curr" << endl;
}
cout << curr << endl;
cout << newCapWord << endl;
(curr->keyword)=newCapWord;
cout << "curr->keyword: " << (curr->keyword) << endl;
(curr->entireTitle)=newCapPhrase;
cout << "curr->entireTitle: " << (curr->entireTitle) << endl;
findPlace=head; findPlaceLag=head;
while(1) {
if ((findPlace->keyword)>(curr->keyword)) {
if (findPlace==head) {
(curr->next)=head;
(head->next)=NULL;
head=curr;
break;
}
else {
while (1) {
if ((findPlaceLag->next)==findPlace) {
(findPlaceLag->next)=curr;
(curr->next)=findPlace;
break;
}
findPlaceLag=(findPlaceLag->next);
}
}
break;
}
else {
if ((findPlace->next)!=NULL) {
findPlace=(findPlace->next);
continue;
}
else {
(curr->next)=(findPlace->next);
(findPlace->next)=curr;
break;
}
}
}
}
wordBegCur=curCursor+1;
}
break;
}
spaceBefore=false;
while (1) {
if (spaceBefore) cout << endl;
cout << (head->entireTitle);
if (head->next==NULL) {
break;
}
spaceBefore=true;
head=(head->next);
}
return 0;
}
|