首页 > 学院 > 开发设计 > 正文

NOIP 2010 普及组 复赛 two 数字统计

2019-11-06 06:37:07
字体:
来源:转载
供稿:网友

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;} 


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表