You can check your answers on my AC code::
import java.io.*;
import java.util.*;
public class Main
{
public static void main(String args[])throws Exception
{
BufferedReader in=new BufferedReader(new
InputStreamReader(System.in));
StringBuffer out=new StringBuffer("");
String s;
while(!(s=in.readLine()).equals("0"))
{
int l=s.length();
int dp[]=new int[l];char ar[];
ar=s.toCharArray();
if(ar[l-1]!='0')
dp[l-1]=1;
for(int j=l-2;j>=0;j--)
{
int a=ar[j]-'0',b=ar[j+1]-'0';
if(j==(l-2) && (10*a+b)<=26)
{
if(a!=0)
dp[j]=1+dp[j+1];
}
else if(j==(l-2) && (10*a+b)>26)
dp[j]=dp[j+1];
else if(j!=(l-2) && (10*a+b)<=26)
{
if(a!=0)
dp[j]=dp[j+1]+dp[j+2];
}
else
{
dp[j]=dp[j+1];
}
}
out.append(dp[0]+"\n");
}
System.out.println(out);
}
}
--
*Regards,*
*Piyush Kapoor,*
*2nd year,CSE
IT-BHU*
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.