您的位置:首页 > 其它

pat甲1049. Counting Ones (30)

2018-04-10 19:35 435 查看
思路见算法笔记《上机训练实践》p198

#include <cstdio>
#include <cstdlib>
#include <string.h>
#include <cmath>
#include <algorithm>
using namespace std;

int n;

int main()
{
scanf("%d",&n);
int sum=0;
int b[11];
int right=0,left=0,now=0;
int mod=0;
int a=1;
while(n!=0)
{
right=right+now*a/10;
now=n%10;
left=n/10;
n=n/10;
if(now==1)
{
sum+=(left)*a+right+1;
}
else if(now==0)
{
sum+=(left)*a;
}
else
{
sum+=(left+1)*a;
}
a*=10;
}
printf("%d\n",sum);
system("pause");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  1049