#include<iostream>using namespace std;int main(void){ //freopen("in.txt", "r", stdin); int N, sum = 0; cin >> N; int wgt = 1;//位权初始1,表示从个位开始 while (N / wgt != 0) { int left = N / (wgt * 10);//表示高位数 int cur = N / wgt % 10;//当前位值 int right = N % wgt;//低位数值 if (cur == 0)//三种情况 sum += left * wgt; else if (cur == 1) sum += left * wgt + right + 1; else sum += (left + 1) * wgt; wgt *= 10;//位权增加 } cout << sum << endl; return 0;}参考自: http://m.blog.csdn.net/article/details?id=38846057
新闻热点
疑难解答