What is wrong with this code for alphacode problem of spoj?

#include<bits/stdc++.h>
using namespace std;
const int mod=48;
int main()
{
string s;
while(1)
{
cin>>s;
int a[s.size()];
a[0]=1;
if(s.size()==1&&s[0]==‘0’)
return 0;
else
{
for(int i=1;i<=s.size()-1;++i)
{
int b=(s[i-1]%48)*10+s[i]%48;
if(b<=26)
{
if(i==1)
a[i]=2;
else
a[i]=a[i-1]+a[i-2];
}
else
a[i]=a[i-1];
}
cout<<a[s.size()-1]<<"\n";
}
}
}

Its the first line of your #include
Otherwise the program is correct
Or you look your program as

No I don’t think so because it is working fine in compiler.The problem that i think is when 0 comes between the digits.

http://ideone.com/Lfjwtz My AC solution, it is easy to understand the cases that can occur and why your code is failing.

1 Like