函数接口定义:
int CountDigit( int number, int digit );
裁判测试程序样例:
#include <stdio.h>
int CountDigit( int number, int digit );
int main()
{
int number, digit;
scanf("%d %d", &number, &digit);
printf(“Number of digit %d in %d: %d\n”, digit, number, CountDigit(number, digit));
return 0;
}
/* 你的代码将被嵌在这里 */
输入样例:
-21252 2
结尾无空行
输出样例:
Number of digit 2 in -21252: 3
结尾无空行
int CountDigit( int number, int digit )
{
int m,n,count=0;
if(number<0)
{
number=(-1)*number;
}
if(number0)
{
count=1;
}
while(number>0)
{
m=number;
n=number%10;
number=m/10;
if(ndigit)
{
count++;
}
}
return count;
}