i am trying to make a palindrome finder using strings
and my program just stops running at the test case input number, so i am guessing that my declaration is wrong.
this is just the even section of the code.
#include<iostream>
#include<string>
usingnamespace std;
int main()
{
int t;
cin>>t;
string number[t];
for(int i=t; i<t; i++)
{
cin>>number[t]; /*i used cin instead of getline because i expect a single stream of numbers with no spaces. getline creats a large gap between my last test case input and my string input. */
int c = number[t].size()/2;
int l = number[t].size();
if(l%2 == 0) //Even
{
if(number[t].at(c) - number[t].at(c-1) > 1)
{
number[t].at(c-1)++;
number[t].at(c)=number[t].at(c-1);
}
elseif(number[t].at(c-1) > number[t].at(c))
{
number[t].at(c)=number[t].at(c-1);
}
for(int x=0 , y=l ; x<=c-1 && y>=c+1 ; x++ , y--)
{
if(number[t].at(x)=number[t].at(y))
{
continue;
}
else {number[t].at(y)=number[t].at(x);}
}
}
}
for(int i=0 ; i<t ; i++)
{
cout<<number[t];
}
}
i need to declare an array of strings whose size and contents are user dependent
sorta like this
first the user inputs the number of inputs he wants.
so if he wants to put in 3 number he will just enter 3
then i want 3 empty strings to be created and accessed sequentially.
so for example
here is the users input
3 ---> no. of numbers to be inputed
457 ---> placed in string0 in the array
*my algo does its work and changes string0's contents to 464
7884---> placed in string1
*changed by algo, becomes 7887 in same string1
45945--->place in string 2
*changed by algo, becomes 45954