题目
题目链接
题解整体思路就是判断每一位上对1的贡献个数。
对于一个数abcdef
,假设我们看c
所在位对1的贡献。
当c=0
时,贡献为ab * 1000
; 当c=1
时,贡献为ab * 1000 + (def+1)
当c>1
时,贡献为ab * 1000 + 1000
1000是因为c所在位的权重为1000。
代码#include
using namespace std;
typedef long long LL;
LL ans;
int n, x, a[100], cnt;
int main()
{
cin >> n;
int x = n;
while (x) {
a[cnt ++] = x % 10;
x /= 10;
}
for (int i = 0, base = 1;i 1) sum += base;
ans += sum;
}
cout
关注
打赏