All pastes #556621 Raw Edit

Miscellany

public text v1 · immutable
·published 2007-06-10 17:56 UTC
rendered paste body
--- 556581	2007-06-10 13:55:32.000000000 -0400
+++ bruce.cpp	2007-06-10 13:55:29.000000000 -0400
@@ -11,6 +11,8 @@
 #include <iostream>
 #include <cstdlib>
 #include <cctype>
+
+#include <cassert>
  
 using namespace std;
 
@@ -20,22 +22,20 @@
     size_t pos;
     
     while( (pos = Test.find_first_of("`~!@#$%^&*()-_=+{}|[]\\:;\"\'<>,.?/\t\r\n")) != string::npos)
-       Test.erase(pos, 1);
+       Test.erase(Test.begin() + pos);
     
     while( (pos = Test.find(" ")) != string::npos)
-       Test.erase(pos, 1);
+       Test.erase(Test.begin() + pos);
     
     while( (pos = Test.find_first_of("ABCDEFGHIJKLMNOPQRSTUVWXYZ")) != string::npos)
        Test[pos] = tolower(Test[pos]);
     
     bool check = false;
     
-    string temp = "";
+    string temp = Test;
+
+    reverse(temp.begin(), temp.end());
     
-    for(int x=Test.length() - 1; x>=0; x--)
-    {
-            temp += Test.at(x);
-    }
     if(Test == temp)
             check = true;
     
@@ -55,19 +55,21 @@
     while(!fin.eof())
     {
         string str;
-        getline(fin, str);
+	getline(fin, str);
         start += str;
     }
  
     string longest = "";
  
+    cout << start << endl << start.length() << endl;
+
     for (int x=0; x < start.length(); x++)
     {
-        for (int y=start.length()-1; y > x + longest.length(); y--)
+        for (int y=start.length()-1; y > x; y--)
         {
             if (tolower(start.at(x)) == tolower(start.at(y)))
             {
-                if (paltest(start.substr(x, y)))
+                if (paltest(string(start.begin() + x, start.begin() + y)))
                 {
                     longest = start.substr(x, y);
                     y=0;