zoj2202

做这道题的时候头都是大了,数组开大了是段错误,开小了是runtime error!用c++写是段错误,用c语言就又WA了,多我这个菜鸟来说,头多大啦!

后来想到了是否是越界,将数变为long long型竟然过了,哈哈!!!!

#include<stdio.h>
#include<string.h>
long long a[10005];
char m[10005];
int main()
{
    int i,length;
    while(scanf("%s",&m))
    {
                 if(m[0]=='0')
                   break;
                 length=strlen(m);
                 for(i=0; i<length; i++)
                  m[i]-='0';
                 a[0]=1;
                 a[1]=1;
                 for(i=1; i<length; i++)
                 {
                          if(m[i]==0)
                           a[i+1]=a[i-1];
                          else if(m[i-1]>0 && m[i-1]<3)
                               a[i+1]=a[i]+a[i-1];
                          else
                               a[i+1]=a[i];
                 }
                 printf("%lld\n",a[length]);
    }
    return 0;
}

你可能感兴趣的:(zoj2202)