函数接口定义:
int Count_Digit ( const int N, const int D );
其中N和D都是用户传入的参数。N的值不超过int的范围;D是[0, 9]区间内的个位数。函数须返回N中D出现的次数。
裁判测试程序样例:
#include <stdio.h>
int Count_Digit ( const int N, const int D );
int main()
{
int N, D;
scanf("%d %d", &N, &D);
printf("%d\n", Count_Digit(N, D));
return 0;
}
/* 你的代码将被嵌在这里 */
int Count_Digit ( const int N, const int D ){
int i=N;
int cnt=0;
if(i<0){有两段一样的,懒得改直接上传了
i=-i;
for(i;i>0;i=i/10){
int t=i%10;
if(t==D){
cnt++;
}
}
}else if(i>10){
for(i;i>0;i=i/10){
int t=i%10;
if(t==D){
cnt++;
}
}
}else if(i<10&&i>=0){
if(i==D){
cnt++;
}
}
return cnt;
}