palindrome finder.

I am trying to make a palindrome finder using a brute force approach to ironically test an algorithim i am using for a spoj classic.
Problem is, i have no idea why my code isn't working :D.
Thanks in advance.

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
 

#include <iostream>
#include <string>
#include <sstream>
using namespace std;

int main()
{


    string t;
    int i, x, s, v;
    istringstream buffer1(t);
    ostringstream buffer2;
    bool f=true;


    getline(cin, t);

    s=t.size()-1;
do{
    buffer1>>v;
    v++;
    buffer2<<v;
    t=buffer2.str();


for (i=0 , x=s ;i<=s/2 && x>s/2; x-- , i++)         //check for palendrum
    {
        if (t[i]==t[x]]){continue;}
       
        else if(t[i] != t[x]){f=false;
            break;}
    }

}while (f = false);

cout<<v<<endl;

}


Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
    string t;
    int i, x, s, v;
    istringstream buffer1(t);
    ostringstream buffer2;
    bool f=true;


    getline(cin, t);

    s=t.size()-1;
do{
    buffer1>>v;


You defined stream buffer1 as empty because at the moment of its definition string t was empty. So the statement

buffer1>>v;

in the do loop has no sense.
i assumed that it's definition changed after i gave string t data.
i am guessing all i have to do is declare buffer1 after the input of string t.
thank you ^^
Topic archived. No new replies allowed.