int numOf1(int n)
{
int factor=1;
int count=0;
while(n/factor!=0)
{
int higher=n/(factor*10);//当前位置的高位组成的数字。
int cur=n/factor%10;//当前位置数字
int lower=n%factor;//当前位置的低位组成的数字。
if(cur==0)
count+=higher*factor;
else if(cur==1)
count+=higher*factor+lower+1;
else
count+=(higher+1)*factor;
factor*=10;
}
return count;
}