PAT-统计个位数字(基础函数题)
2015-12-23 21:09
274 查看
本题要求实现一个函数,可统计任一整数中某个位数出现的次数。例如-21252中,2出现了3次,则该函数应该返回3。
其中
9]区间内的个位数。函数须返回
函数接口定义:
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;
}
/* 你的代码将被嵌在这里 */
输入样例:
-21252 2
输出样例:
3
程序代码 int Count_Digit(const int N, const int D) { int count,temp,x; x=N; if(x<0) x=-x; do{ temp=x%10; if(temp==D) count++; x=x/10; }while(x>0); return count; }
相关文章推荐
- Shell
- UFLDL教程答案(7):Exercise:Learning color features with Sparse Autoencoders
- android service 详解
- poj 2253 Frogger【最短路】
- JAVA:Collections类的shuffle()方法
- TCP/IP详解学习笔记
- 选择排序
- IP地址分类
- UICollectionViewCell
- muduo源码分析:日志相关类(1)
- Android之布局合并优化
- JUnit多线程Test
- 获取图片base64编码的几种方法
- 禁止触屏滑动touchmove方法介绍
- UI01_UILabel
- document.body.scrollTop与document.documentElement.scrollTop兼容
- monog和github学习
- as well as
- PHP中逻辑运算符and/or与||/&&的一个坑
- asp中遇到的几个问题——数据库连接,几个常见控件的使用问题及其解决