Codeforces Round #308 (Div. 2) Vanya and Books

来源:互联网 发布:sql 多个查询结果合并 编辑:程序博客网 时间:2024/05/21 09:22

题目链接:http://codeforces.com/contest/552/problem/B
题意:就是求有几个数字;
eg:13:1 2 3 4 5 6 4 7 8 9 1 0 1 1 1 2 1 3
一共17个数字

#include <iostream>using namespace std;long long a[12]={0,9,99,999,9999,99999,999999,9999999,99999999,999999999,9999999999};int main(){    long long m;    while(cin>>m)    {        long long  k=1,sum=0;注意是long long         if(m<10)        {            cout<<m<<endl;            continue;        }        else        {            for(int i=1; i<=10; i++)            {                k*=10;                if(m<k)                {                    sum+=(m-k/10+1)*i;                    break;                }                else                    sum+=(a[i]-a[i-1])*i;            }            cout<<sum<<endl;        }    }    return 0;}
0 0