Hello, I am new here and also new in C++. I want to learn what my mistake is. Thanks for your help. Here my code is.
#include <stdio.h>
#include <sstream>
using namespace std;
bool isPalindrome (string word)
{
for (unsigned int i = 0; i < (word.length()/2); i++)
if (word[i] != word[(word.length()-1)-i])
return false;
return true;
}
void palindrome(int K)
{
bool palin = false;
while(!palin)
{
stringstream ss;
ss << K;
string s1 = ss.str();
palin = isPalindrome(s1);
if(palin)
printf("%d\n", K);
K++;
}
}
int main()
{
int trial,temp;
scanf("%d", &trial);
int K[trial];
for(int i = 0; i < trial; i++)
{
scanf("%d", &temp);
K[i] = temp;
palindrome(K[i] + 1);
}
return 0;
}
How can i decrease time?