6,连续多位数的最大乘积

 

 1 int test6(int num){ //最大连续几位,连续位数太多可以更改s的类型
 2     // char a[] = "7316717653133062491922511420752963450";
 3     char a[] ="1234560693212";
 4     int len = strlen(a);
 5     printf("%d\n",len);
 6     int i,k;
 7     int j=1,s=0,sum;
 8     for(i=0; i<=len-num; i++){
 9         sum=1;
10         for(k=0;k<num; k++){
11             j = a[i+k]-0x30;
12             sum *= j;
13             if(j == 0){
14                 i+=k;
15                 break;
16             }     
17         }
18         if(s<sum){
19             s = sum;
20         }
21     }
22     return s;
23 }

 

posted @ 2020-07-11 10:17  鱹鱹  阅读(212)  评论(0编辑  收藏  举报