从低位向高位分析总结,划分出left,right,now。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;
int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
int n = 0;
scanf("%d", &n);
int left, now, right;
int a = 1, ans = 0;
while (n/a != 0)
{
left = n/(a*10);
right = n%a;
now = n%(a*10)/a;
if (now == 1)
ans += left*a + right + 1;
else if (now == 0)
ans += left*a;
else
ans += (left+1)*a;
a *= 10;
}
printf("%d", ans);
return 0;
}