题解 | #[NOIP2010]数字统计#

[NOIP2010]数字统计

https://www.nowcoder.com/practice/179d9754eeaf48a1b9a49dc1d438525a

#include<stdio.h>
#include<string.h>

int test(int x)
{
    char arr[10]={0};
    sprintf(arr,"%d",x);
    int right = strlen(arr)-1;
    int j = 0;
    int count=0;
    for(j = 0;j<=right;j++)
    {
        if(arr[j]=='2')
        {
            count++;
        }
    }
    return count;

}
int main()
{
    int l,r;
    scanf("%d %d",&l,&r);
    int i = 0;
    int sum = 0;
    for(i=l;i<=r;i++)
    {
        sum+=test(i);
    }
    printf("%d\n",sum);
    return 0;

}

全部评论

相关推荐

野猪不是猪🐗:我assume that你must技术aspect是solid的,temperament也挺good的,however面试不太serious,generally会feel style上不够sharp
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务