您的位置:首页 > 其它

1049. Counting Ones (30)

2013-11-15 12:37 169 查看
1049. Counting Ones (30)

#include <stdio.h>
class CA
{
public:
void run();
int n,num;
};
void CA::run()
{
scanf("%d",&n);
int r,x,y,m;
num=0;
r=1;x=n;
while(x>0)
{
m=x%10;
y=n%r;
x=x/10;
if(m>1)
{
num+=(x+1)*r;
}
else if(m==1)
{
num+=x*r+y+1;
}
else if(m<1)
{
num+=x*r;
}
r*=10;
}
printf("%d\n",num);
}

int main()
{

// freopen("test.in","r",stdin);
CA *a=new CA;
a->run();
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Counting Ones