#include #include using namespace std; const bool DEBUG = false; const int MAXSIG = 100; // max # of sig words and max # times any letter in acronym appears in text const int MAXINSIG = 100; const int MAXLEN = 100; // maximum length of acronym long table[MAXLEN][MAXSIG][MAXSIG]; // table[i][j][k] = # of time acronym[0..i-1] appears // in text[0..j-1] using first k sig words string dict[MAXINSIG]; int nDict; string acronym, text; int alen, tlen; int startSig[MAXSIG+1], numSig; int startPos[MAXLEN]; // earliest spot we can start looking for each // letter in acronym int endPos[MAXLEN]; // acronym[i] must start before endPos[i] bool isInsig(string s) { for(int i=0; i= 'a' && s[i] <= 'z') s[i] += 'A'-'a'; ans += s[i]; } return ans; } bool process() { text = ""; numSig = 0; int loc = 0; while (true) { string word; cin >> word; if (word == "CASE") return false; if (!isInsig(word)) { startSig[numSig++] = loc; text += capitalize(word); loc += word.length(); } if (cin.get() != ' ') break; } startSig[numSig] = loc; // determine starting and ending locations // for each letter in acronym for(int i=0; i 0) startPos[i] = startSig[index]; else startPos[i] = startSig[0]+i; if (i < numSig-1) endPos[i] = startSig[i+1]; else endPos[i] = startSig[numSig] - (acronym.length()-i-1); } /* cout << text << endl; for(i=0; i> nDict; while (nDict != 0) { for(i=0; i> dict[i]; } cin >> acronym; while (process()) { alen = acronym.length(); tlen = text.length(); long ans = fillTable(acronym, text); if (ans > 0) cout << acronym << " can be formed in " << ans << " ways" << endl; else cout << acronym << " is not a valid abbreviation" << endl; cin >> acronym; } cin >> nDict; } }