Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
秒杀,贴代妈#include <iostream> #include <stdio.h> using namespace std; int a,b; int p10[9] = {1,10,100,1000,10000,100000,1000000,10000000,100000000}; int intersect(int s1, int e1, int s2, int e2){ int s = (s1>s2)? s1 : s2; int e = (e1<e2)? e1 : e2; if(s > e) return 0; return e-s+1; } int main() { while(1){ scanf("%d%d", &a, &b); if(a == 0 && b == 0) return 0; if(a > b){ int temp = a; a = b; b = temp; } int ans[10] = {0}; for(int k = 1; k <= 8; k++){ int t1 = a/p10[k], r1 = a%p10[k], t2 = b/p10[k], r2 = b%p10[k]; //cout << t1 << " " << r1 << " " << t2 << " " << r2 << endl; if(t1 == t2){ if(t1 != 0) ans[0] += intersect(0,p10[k-1]-1,r1,r2); for(int j = 1; j <= 9; j++) ans[j] += intersect(j*p10[k-1], (j+1)*p10[k-1]-1, r1, r2); } else{ int zqjgs = t2-t1-1; for(int j = 0; j <= 9; j++) ans[j] += zqjgs * p10[k-1]; if(t1!=0) ans[0] += intersect(0,p10[k-1]-1,r1,p10[k]-1); for(int j = 1; j <= 9; j++) ans[j] += intersect(j*p10[k-1],(j+1)*p10[k-1]-1, r1, p10[k]-1); for(int j = 0; j <= 9; j++) ans[j] += intersect(j*p10[k-1],(j+1)*p10[k-1]-1, 0, r2); } } for(int i = 0; i < 10; i++) cout << ans[i] << " "; cout << endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator