NOIP 2010 普及组 复赛 two 数字统计
2017-03-06 16:32
309 查看
NOIP 2010 普及组 复赛 two 数字统计
//洛谷 p1179 数字统计
//难度:入门难度
//考点:输入,输出 ,整数四则运算,取整,取模,函数编写,栈,算法时间复杂度
//适用:小学生
//感悟:原本以为该题需要用什么技巧。一看<=100000,立马想到枚举,采用分离个十百千万的做法,数出2的个数。
附上AC代码,编译环境Dev-C++4.9.9.2
#include <stdio.h>
int count2(int a){
int top=-1;
int b[10];
int i;
int count=0;
while(a){
top++;
b[top]=a%10;
a/=10;
}
for(i=0;i<=top;i++)
if(b[i]==2)
count++;
return count;
}
int main(){
int L,R;
int ans=0;
int i;
scanf("%d%d",&L,&R);
for(i=L;i<=R;i++)
ans+=count2(i);
printf("%d\n",ans);
return 0;
}
//洛谷 p1179 数字统计
//难度:入门难度
//考点:输入,输出 ,整数四则运算,取整,取模,函数编写,栈,算法时间复杂度
//适用:小学生
//感悟:原本以为该题需要用什么技巧。一看<=100000,立马想到枚举,采用分离个十百千万的做法,数出2的个数。
附上AC代码,编译环境Dev-C++4.9.9.2
#include <stdio.h>
int count2(int a){
int top=-1;
int b[10];
int i;
int count=0;
while(a){
top++;
b[top]=a%10;
a/=10;
}
for(i=0;i<=top;i++)
if(b[i]==2)
count++;
return count;
}
int main(){
int L,R;
int ans=0;
int i;
scanf("%d%d",&L,&R);
for(i=L;i<=R;i++)
ans+=count2(i);
printf("%d\n",ans);
return 0;
}
相关文章推荐
- NOIP2010-普及组复赛-第一题-数字统计
- luogu1179 数字统计(NOIP2010普及组第1题)
- 全国信息学奥林匹克联赛(NOIP2010)复赛 1.数字统计 解题报告
- [NOIP2010] (普及组) 数字统计
- [Noip2010普及组]数字统计
- NOIP2010普及组--数字统计
- NOIP 2010普及组 数字统计
- noip2010 数字统计 (统计某一数字区间中,2出现的次数)
- NOIP2011-普及组复赛-第一题-数字反转
- 洛谷-统计数字-NOIP2007提高组复赛
- NOIP2011-普及组复赛-第二题-统计单词数
- NOIP2010-普及组复赛-第二题-接水问题
- NOIP2010第二题 ---数字统计(摘自洛谷题解)
- NOIP 2011 普及组 复赛 reverse 数字反转
- 数字统计(2010年NOIP全国联赛普及组)
- codevs 1126 数字统计 2010年NOIP全国联赛普及组 x
- 数字统计(NOIP2010)
- NOIP 2010 普及组 复赛 water 接水问题
- NOIP2007 提高组 复赛 count 统计数字
- 05:统计单词数【NOIP2011复赛普及组第二题】