您的位置:首页 > 其它

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;

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: