当前位置:网站首页>Digital DP example

Digital DP example

2022-06-13 11:02:00 I can screw the bottle cap when I am born again

 Insert picture description here

empty

 Insert picture description here

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
int get(vector<int> num,int l,int r)
{
    
    int res = 0;
    for (int i=l;i>=r;i--) res = res*10 +num[i];
    return res;
}
int power10(int u)
{
    
    int res =1;
    while (u--) res*=10;
    return res;
} 
int count (int n,int x)
{
    
    if (!n) return 0;
    vector<int> num;
    while (n)
    {
    
        num.push_back(n%10);
        n/=10;
    }
    n = num.size();
    int res = 0;
    
    for (int i=n-1-!x;i>=0;i--)
    {
    
        if (i<n-1)
        {
    
            res += get(num,n-1,i+1)*power10(i);
            if (!x) res-=power10(i);
        }
        if (x==num[i]) res+=get (num,i-1,0)+1;
        else if (x<num[i]) res+=power10(i);
    }
    return res;
} 
int main(){
    
    int a,b;
    while (cin>>a>>b,a)
    {
    
        if (a>b) swap(a,b);
        for (int i=0;i<=9;i++)
        cout<< count(b,i)-count(a-1,i)<<' ';
        cout<<endl;
    }
    return 0;
}
原网站

版权声明
本文为[I can screw the bottle cap when I am born again]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/164/202206131056568091.html