题目描述
blablabla
样例
blablabla
- 0和1-9需要特判一下
- get_num()中l比r大
C++ 代码
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define mst(s,_s) memset(s, _s, sizeof(s))
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
const int N = 1e6+100;
int T,n,m;
int get_num(vector<int>nums,int l,int r)
{
int res=0;
for(int i=l;i>=r;i--)
res=res*10+nums[i];
return res;
}
int get10(int x)
{
int res=1;
while(x--)
{
res*=10;
}
return res;
}
// 1到n之间,有多少x
int dp(int n,int k)
{
if(!n) return 0;
vector<int>nums;
while(n){
nums.push_back(n%10);
n/=10;
}
int res=0;
for(int i=nums.size()-1-!k;i>=0;i--)
{
int x=nums[i];
if(i<nums.size()-1)
{
res+=get_num(nums,nums.size()-1,i+1)*get10(i);
if(!k) res-=get10(i);
}
if(k==x) res+=get_num(nums,i-1,0)+1;
if(k<x) res+=get10(i);
}
return res;
}
int main() {
int l,r;
while(cin>>l>>r)
{
if(!l || !r) break;
if(l>r) swap(l,r);
for(int i=0;i<=9;i++)
cout<<dp(r,i)-dp(l-1,i)<<' ';
cout<<endl;
}
return 0;
}