ACODE-SPOJ

Getting WA in following code, can anyone figure out a mistake for me?

Did you consider the case when s[i]==‘0’ ?

Take a look here, when s[i]==‘0’

signed main(){
    FASTER;
    string s;cin>>s;
    int dp[100000];
    while(s!="0"){
        int n=s.size();
        dp[0]=1;
        for(int i=1;i<n;i++){
            int numm=((s[i-1]-'0')*10+(s[i]-'0'));
            if(numm>=10 && numm<=26 && s[i]!='0'){
                if(i-2>=0)
                dp[i]=dp[i-1]+dp[i-2];
                else dp[i]=2;
            }else{
                dp[i]=dp[i-1];
            }
            if(s[i]=='0'){
                if(i-2>0)
                dp[i]=dp[i-2];
                else dp[i]=1;
            }
        }
        cout<<dp[n-1]<<"\n";
        cin>>s;
    }
}
1 Like