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;
}
#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;
}
相关文章推荐
- Ext.js5表单的文件上传(toast)(30)
- 20151228 ocp 053 1-30
- 【Android 界面效果30】Android中ImageSwitcher结合Gallery展示SD卡中的资源图片
- 1087. All Roads Lead to Rome (30)
- 经典.net面试题目及答案(11~30)
- 1076. Forwards on Weibo (30)
- 1045. Favorite Color Stripe (30)
- 1004. Counting Leaves (30)
- 1030. Travel Plan (30)
- Vulkan in 30 minutes
- 创建安卓应用的 30 个经验教训
- 30. 奇怪的梦境(拓扑排序)
- De 30: Decoupling Linear Systems with Constant Coefficients
- PAT (Advanced Level) Practise 1030 Travel Plan (30)
- PAT甲级1001-Public Bike Management (30)
- Recover the Smallest Number (30)
- 滑动RecyclerView时出现异常: java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 6(offset:6).state:30
- PAT (Advanced Level) Practise 1057 Stack (30)
- PAT (Advanced Level) Practise 1068 Find More Coins (30)
- PAT (Advanced Level) Practise 1087 All Roads Lead to Rome (30)