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

简介:

题目链接: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;
}
目录
相关文章
|
1月前
|
机器学习/深度学习 人工智能 测试技术
Codeforces Round 960 (Div. 2)
Codeforces Round 960 (Div. 2)
|
机器学习/深度学习 人工智能 移动开发
.Codeforces Round 883 (Div. 3)
Codeforces Round 883 (Div. 3)
Codeforces Round #192 (Div. 2) (329A)C.Purification
Codeforces Round #192 (Div. 2) (329A)C.Purification
45 0
Codeforces Round #742 (Div. 2)
Codeforces Round #742 (Div. 2)
47 0
Codeforces Round #640 (Div. 4)
Codeforces Round #640 (Div. 4)
89 0
|
机器学习/深度学习
Codeforces Round #723 (Div. 2)B. I Hate 1111
Description You are given an integer x. Can you make x by summing up some number of 11,111,1111,11111,…? (You can use any number among them any number of times). For instance, 33=11+11+11 144=111+11+11+11
178 0
Codeforces Round #723 (Div. 2)B. I Hate 1111
|
机器学习/深度学习 算法 C++