I don't get it, my solution seems to be working when I test it and test samples from the text work. But when I send it, it fails on 14. and 15. test samples i think. This is my code:
#include <iostream>
#include <string>
#include <ctype.h>
using namespace std;
int palindrom (string a)
{
string b;
for (int i=a.size()-1;i>=0;i--)
{
a[i]=tolower(a[i]);
b+=a[i];
}
if (a==b) return 1; else return 0;
}
int main ()
{
string a,b;
int max=0,zbr=0;
getline (cin,a);
for (int i=0;i<=a.size()-1;i++)
{
b.clear();
zbr=0;
while (1==1)
{
if (i<=a.size())
{
if ((a[i]>=65 && a[i]<=122)||(a[i]>=48 && a[i]<=57))
{
goto abc;
}
}
if (zbr>0) goto pal;
goto poc;
abc:;
b+=a[i];
zbr++;
i++;
}
pal:;
if (palindrom(b)==1)
{
max++;
}
poc:;
}
cout<<max<<endl;
return 0;
}
I hope somebody who already solved this task can help me find my mistake.
#include <iostream>
#include <string>
#include <ctype.h>
using namespace std;
int palindrom (string a)
{
string b;
for (int i=a.size()-1;i>=0;i--)
{
a[i]=tolower(a[i]);
b+=a[i];
}
if (a==b) return 1; else return 0;
}
int main ()
{
string a,b;
int max=0,zbr=0;
getline (cin,a);
for (int i=0;i<=a.size()-1;i++)
{
b.clear();
zbr=0;
while (1==1)
{
if (i<=a.size())
{
if ((a[i]>=65 && a[i]<=122)||(a[i]>=48 && a[i]<=57))
{
goto abc;
}
}
if (zbr>0) goto pal;
goto poc;
abc:;
b+=a[i];
zbr++;
i++;
}
pal:;
if (palindrom(b)==1)
{
max++;
}
poc:;
}
cout<<max<<endl;
return 0;
}
I hope somebody who already solved this task can help me find my mistake.