The Counting Problem UVA - 1640

结合紫书的分析,按照诸位判断并且计算即可,具体实现见如下代码:

#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<deque>
#include<functional>
using namespace std;

typedef long long LL;


LL res1[10], res2[10];

void solve(char data[],LL res[]){
	int length = strlen(data);
	int t = 1;
	for (int i = 0; i < length-1; i++){
		t *= 10;
		res[0] -= t;
	}
	for (int i = 0; i < length; i++){
		int temp = data[i] - '0';
		for (int j = 0; j < temp; j++){
			res[j] += t;
		}
		for (int j = 0; j < 10; j++){
			res[j] += temp*((length - 1 - i)*t / 10);
		}
		res[temp] += atoi(data + i + 1)+1;
		t /= 10;
	}
}

int main(){
	LL a, b;
	while (cin >> a >> b){
		if (a == 0 && b == 0) break;
		char data1[10], data2[10];
		if (a > b) swap(a,b);
		a--;
		memset(data1, 0, sizeof(data1));
		memset(data2, 0, sizeof(data2));
		sprintf(data1, "%d", a);
		sprintf(data2, "%d", b);
		memset(res1, 0, sizeof(res1));
		memset(res2, 0, sizeof(res2));
		solve(data1, res1);
		solve(data2, res2);
		for (int i = 0; i < 9; i++)
			cout << res2[i] - res1[i] << " ";
		cout << res2[9] - res1[9] << endl;
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值