求调,样例都过不了!qwq
查看原帖
求调,样例都过不了!qwq
654763
smallpeople楼主2024/7/27 16:33
#include<bits/stdc++.h>
using namespace std;
#define ll long long

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 count(ll 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) * pow(10,i);
			if(!x)res -= pow(10,i);
		}
		if(num[i] == x)res += get(num,i - 1,0) + 1;
		else if(num[i] > x)res += pow(10,i);
	}
}

int main()
{
	ll a,b;
	cin>>a>>b;
	
	for(int i = 0;i <= 9;i ++)
		cout<<count(b,i) - count(a - 1,i)<<" ";
	
	return 0;
}

蒟蒻代码↑

2024/7/27 16:33
加载中...