主题:有点乱,请高手赐教!!不胜感激!!
There are two numbers m and n, now Zero want to choose an consecutive part of m to form a new number p, so that p can be divide exactly by n. Could you write a program to calculate how many ways are there to choose p?
Input
Input will consist of multiple test cases.
For each case, there will be two numbers, m and n.
The number of m's digits is less than 10000, and there is no '0' in m. 1 &le n &le 100
Output
Output a single number, the ways to choose p.
Sample Input
22 2
111 1
111 2
123 3
Sample Output
3
6
0
3
Hints: in case "123 3",the ways to choose are "12","3","123"
题的大概也就是输入m和n 这两个数,现在把m的部分数构成新的数p(数之间是相连的),要求p能被n整除,则输出p的多少种可能(m是0到10000之间,n为1到100);
下面是我所写的程序,是逻辑性的错误,但一直找不到错误所在,希望高手进来指导一下,不胜感激!!谢谢!~
#include<stdio.h>
#define SIZE 5
void Jishu(int m1,int n1);
void Fenjie1(int m2);
int Zuhe( int j );
void Fenjie2(int m3);
int count=0;
int arry0[SIZE], arry1[SIZE], arry2[SIZE], arry3[SIZE];
int k;
int main(void)
{
for(int i0=0; i0<SIZE;i0++)
arry0[i0]=arry1[i0]=arry2[i0]=arry3[i0]=0;
int m, n,num;
printf("The number of m and n:");
scanf("%d",&num);
for(int i=0;i<num;i++)
{
scanf("%d,&d\n",&m,&n);
Jishu(m,n);
Fenjie1(m);
while(k!=1)
{
m=Zuhe(k);
Jishu(m,n);
Fenjie2(m);
}
for(int l1=0;arry1[l1]!=0;l1++)
Jishu(arry1[l1],n);
for(int l2=0; arry2[l2]!=0;l2++)
Jishu(arry2[l2],n);
for(int l3=0; arry3[l3]!=0;l3++)
Jishu(arry3[l3],m);
printf("%d\n",count);
count=0;
for(int i0=0; i0<SIZE;i0++)
arry0[i0]=arry1[i0]=arry2[i0]=arry3[i0]=0;
}
return 0;
}
void Jishu(int m1,int n1)
{
if(m1%n1==0)
count++;
}
void Fenjie1(int m2)
{
int i=0;
for(i=0;m2<10;i++)
{
arry0[i]=arry1[i]=m2%10; //取余存入数组中
arry2[i]=m2/10; //取整存入数组中
m2=arry2[i];
}
k=i--;
}
int Zuhe( int j )
{
int m0=0;
for(; j>=0;j--)
for(; j>0;j--)
arry0[j]*=10;
m0+=arry0[j];
return m0;
}
void Fenjie2(int m3)
{
int i;
for(i=0;m3<10;i++)
{
arry3[i]=m3/10;
m3=arry3[i];
}
}
Input
Input will consist of multiple test cases.
For each case, there will be two numbers, m and n.
The number of m's digits is less than 10000, and there is no '0' in m. 1 &le n &le 100
Output
Output a single number, the ways to choose p.
Sample Input
22 2
111 1
111 2
123 3
Sample Output
3
6
0
3
Hints: in case "123 3",the ways to choose are "12","3","123"
题的大概也就是输入m和n 这两个数,现在把m的部分数构成新的数p(数之间是相连的),要求p能被n整除,则输出p的多少种可能(m是0到10000之间,n为1到100);
下面是我所写的程序,是逻辑性的错误,但一直找不到错误所在,希望高手进来指导一下,不胜感激!!谢谢!~
#include<stdio.h>
#define SIZE 5
void Jishu(int m1,int n1);
void Fenjie1(int m2);
int Zuhe( int j );
void Fenjie2(int m3);
int count=0;
int arry0[SIZE], arry1[SIZE], arry2[SIZE], arry3[SIZE];
int k;
int main(void)
{
for(int i0=0; i0<SIZE;i0++)
arry0[i0]=arry1[i0]=arry2[i0]=arry3[i0]=0;
int m, n,num;
printf("The number of m and n:");
scanf("%d",&num);
for(int i=0;i<num;i++)
{
scanf("%d,&d\n",&m,&n);
Jishu(m,n);
Fenjie1(m);
while(k!=1)
{
m=Zuhe(k);
Jishu(m,n);
Fenjie2(m);
}
for(int l1=0;arry1[l1]!=0;l1++)
Jishu(arry1[l1],n);
for(int l2=0; arry2[l2]!=0;l2++)
Jishu(arry2[l2],n);
for(int l3=0; arry3[l3]!=0;l3++)
Jishu(arry3[l3],m);
printf("%d\n",count);
count=0;
for(int i0=0; i0<SIZE;i0++)
arry0[i0]=arry1[i0]=arry2[i0]=arry3[i0]=0;
}
return 0;
}
void Jishu(int m1,int n1)
{
if(m1%n1==0)
count++;
}
void Fenjie1(int m2)
{
int i=0;
for(i=0;m2<10;i++)
{
arry0[i]=arry1[i]=m2%10; //取余存入数组中
arry2[i]=m2/10; //取整存入数组中
m2=arry2[i];
}
k=i--;
}
int Zuhe( int j )
{
int m0=0;
for(; j>=0;j--)
for(; j>0;j--)
arry0[j]*=10;
m0+=arry0[j];
return m0;
}
void Fenjie2(int m3)
{
int i;
for(i=0;m3<10;i++)
{
arry3[i]=m3/10;
m3=arry3[i];
}
}