#include #include const int MAX_LENGTH = 40; typedef char string[MAX_LENGTH]; string stack; string queue; int topS = -1; int topQ = -1; void pushS(char ch) { if (topS < MAX_LENGTH ) stack[++topS] = ch; } char popS() { if (topS > -1) return stack[topS--]; else return ' '; } bool emptyS() { return (topS == -1); } void pushQ(char ch) { if ( topQ == -1 ) queue[++topQ] = ch; else { topQ++; for (int i=topQ; i>0; i--) { queue[i] = queue[i-1]; } queue[0] = ch; } } char popQ() { if (topQ > -1) return queue[topQ--]; else return ' '; } bool emptyQ() { return (topQ == -1); } bool isPalindrome() { while ( !emptyS() && !emptyQ() ) { char s = popS(); char p = popQ(); if ( s != p ) return false; } return true; } void main() { string strIn; string result = ""; ifstream InFile("palindromes.txt"); ofstream OutFile("13.txt"); while ( InFile.peek() != EOF ) { InFile.getline(strIn, MAX_LENGTH); char *upStr = strupr( strdup( strIn ) ); int l = strlen(upStr); for (int i=0; i='A' && upStr[i]<='Z' ) { pushQ(upStr[i]); pushS(upStr[i]); } } if ( isPalindrome() ) strcpy(result, "T:"); else strcpy(result, "F:"); OutFile << result << strIn << "\n"; topQ = -1; topS = -1; } OutFile.close(); InFile.close(); }