poj 3286 How many 0's?
来源:互联网 发布:ubuntu 16.04 ati驱动 编辑:程序博客网 时间:2024/06/05 11:39
How many 0's?
Time Limit: 1000MS Memory Limit: 65536KB 64bit IO Format: %I64d & %I64u
[Submit] [Go Back] [Status]
Description
A Benedict monk No.16 writes down the decimal representations of all natural numbers between and including m and n, m ≤ n. How many 0's will he write down?
Input
Input consists of a sequence of lines. Each line contains two unsigned 32-bit integers m and n, m ≤ n. The last line of input has the value of m negative and this line should not be processed.
Output
For each line of input print one line of output with one integer number giving the number of 0's written down by the monk.
Sample Input
10 11100 2000 5001234567890 23456789010 4294967295-1 -1
Sample Output
122929876543043825876150
[Submit] [Go Back] [Status]
呵呵基本和上一个题一样。。不过只求m——n之间所有数的0的个数
简单。。
Problem: E User: sdau_09_zysMemory: 164 KB Time: 110 MSLanguage: C++ Result: AcceptedPublic:
#include <iostream>#include <string>using namespace std;__int64 a,b;__int64 ansa[10],ansb[10];void count_digits(__int64 s,__int64 ans[],__int64 times=1)//求1-s之间的所有数中 0的个数,1的个数,2.....其中ans[0...9]为返回值{ __int64 i,d,p; if (s <= 0)return ; d = s % 10; p = s / 10; for (i = 1;i <= d;i ++)ans[i] += times; while(p > 0) { ans[p % 10] += (d + 1) * times; p = p / 10; } for (i = 0;i <= 9;i ++)ans[i] += times * (s / 10); times *= 10; count_digits((s / 10)-1,ans,times); return ;}int main(){ //int i,j; bool is;while(scanf("%I64d%I64d",&a,&b) != EOF){ if(a==-1&&b==-1)break; if(!a&&!b){printf("1\n");continue;} is=false; memset(ansb,0,sizeof(ansb)); memset(ansa,0,sizeof(ansa)); if (a > b) { swap(a,b); } //if(a==b)is=true; if(a==0)is=true; if(a>0)a --; if (b > a) { count_digits(b,ansb); count_digits(a,ansa); } if(is)ansb[0]+=1; //if(is)printf("%I64d\n",2*(ansb[0]-ansa[0]));else printf("%I64d\n",ansb[0]-ansa[0]);}return 0;}
- poj 3286 How many 0's?
- POJ 3286How many 0's?
- poj 3286 How many 0's?
- poj 3286 How many 0's?
- poj-3286-How many 0's?
- POJ 3286 How many 0's?
- POJ 3286 How many 0's?
- poj-3286 How many 0's?
- poj 3286 How Many 0's?
- POJ 3286 How many 0’s?
- poj 3286 How many 0's? (数位DP+ 统计)
- poj 3286 How many 0's? --- 数位dp
- How many 0's? - POJ 3286 数位dp
- poj 3286 How many 0's? 按位统计
- POJ 3286 How many 0's?(数论)
- POJ 3286 How many 0's?(数位DP)
- POJ 3286 How many 0's? (数位dp)
- POJ 3286 How many 0's?(数位dp)
- 学习资料2900篇(4~6)
- poj 3252 Round Numbers
- set -o vi
- 用sql语句dbcc log 查看SQL Server 数据库的事务日志
- 视图相关的结构
- poj 3286 How many 0's?
- 用c#读取并分析sql2005日志
- poj 2282 The Counting Problem
- 指针成员的类的COPY
- 抓取指定的Html
- SQLServer2005数据库日志文件损坏的情况下如何恢复数据库
- 怎么查看和获取SQL Server实例名
- Android开发之初识Camera图像采集
- poj 3370 Halloween treats