首页 > 其他 > 详细

统计n个数中的1的个数

时间:2015-11-01 13:55:35      阅读:152      评论:0      收藏:0      [点我收藏+]
#include<iostream>
#include<cstdio>
#include<stdlib.h>
using namespace std;
int main()
{
    freopen("rand.txt","r",stdin);
    freopen("xuduoshudeyi.out","w",stdout);
    int n,count=0,x;
    scanf("%d",&n);
    for(int i=1;i<=n;++i)
    {
        scanf("%d",&x);
        for(int j=1;j<=x;++j)
        {
        int k=j;
        while(k>0)
             {
            if(k%10==1)
            count+=1;
            k/=10;
             }
        }
    }
    printf("%d",count);
    fclose(stdin);
    fclose(stdout);
    system("xuduoshudeyi.out");
    return 0;
} 

输入样例

12 2462 7740 7040 7260 9142 491 5645 7314 4341 1401 3743 7610 

输出样例

30236

统计n个数中的1的个数

原文:http://www.cnblogs.com/gbygby/p/4927544.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!