1的数目
前言国庆7天长假,自己还是要有学习计划的,前两天需要找回之前的状态,预计10道ACM题目和看完《cracking the coding interview》。话说,还算顺利的拿到了阿里的系统工程师offer,虽然没最终确定,估计问题不大了,毕竟短信都收到了,很开心却让我丧失了很多的动力,趁着国庆长假找回失去的状态,记得刚读研就是利用国庆长假看完《php和myslq开发》,从而走上了开发服务器端应用层API的道路
题目
/** * 数学方法 * * T = O(lnN/ln10) */ int calTwo(int n){int low, high, cur, factor = 1, num = 0;while (n / factor) {cur = (n / factor) % 10;low = n - (n / factor) * factor;high = n / (factor * 10);switch (cur) {case 0 :case 1 :num += high * factor;break;case 2 :num += high * factor + low + 1;break;default :num += (high + 1) * factor;break;}factor *= 10;}return num;}