UVA11038 How Many O's?
原创
©著作权归作者所有:来自51CTO博客作者lzyle的原创作品,请联系作者获取转载授权,否则将追究法律责任
题目链接:传送门
貌似可以数位dp
但这种思路还是很不错的
/**
* @Date: 2019-04-01T14:41:49+08:00
* @Last modified time: 2019-04-01T14:41:49+08:00
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <algorithm>
#include <climits>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define
#define
using namespace std;
typedef long long ll;
ll calc(ll l) {
ll r = 0, ans = 1, w = 1;
while (l >= 10) {
ll m = l % 10;
l /= 10;
if (m) ans += l * w;
else ans += (l - 1) * w + r + 1;
r += m * w;
w *= 10;
}
return ans;
}
ll a, b;
int main(int argc, char const *argv[]) {
while (cin >> a >> b and ~a and ~b) cout << calc(b) - calc(a - 1) << endl;
}