I'm particularly stupid with this question. As a string, the code becomes bloated and cumbersome
Time-out reason: give each number to hit the table, and finally add the number of intervals, if there are a large number of groups, such as 1~999987,4~777777 ... Complexity is the point of magnitude
Modified: The total number of 0~i per element I stored in the table
#include <iostream>#include<cstdlib>#include<cstring>#include<algorithm>#include<cstdio>using namespacestd;Const intMax =1000000;intA[max];intB[max];intMain () {intx, y; Memset (A,0,sizeof(a)); Memset (A,0,sizeof(b)); for(inti = the; I <1000000; i++) { intm =0; intn =0; Chars[8]; intCNT =0; //itoa (i,s,10); //cout << S; intj =i; while(J >0) { //This mistake is also often committedS[CNT] = j%Ten+'0'; J= j/Ten; //cout << J << Endl;CNT + +; } intL =strlen (s); if(Strstr (s),"5") &&strstr (S,"2") &&strstr (S,"1")) M++; if(Strstr (s)," the")) n++; A[i]= a[i-1] + M;//record 521 numbers between 0 and IB[i] = b[i-1] +N; //cout << B[i]; } intCN =1; while(SCANF ("%d%d", &x,&y) = =2) { intp = a[y]-a[x-1],q = b[y]-b[x-1]; printf ("Case %d:%d%d\n", cn,p,q); CN++; } return 0;}
My smelly Long code
#include<stdio.h>inta[2][1000001]={0};intMain () {intk=0, i,sum=0; for(i=1; i<=1000000; i++){if((i%Ten==5|| (i/Ten)%Ten==5|| (i/ -)%Ten==5|| (i/ +)%Ten==5|| (i/10000)%Ten==5|| (i/100000)%Ten==5) && (i%Ten==2|| (i/Ten)%Ten==2|| (i/ -)%Ten==2|| (i/ +)%Ten==2|| (i/10000)%Ten==2|| (i/100000)%Ten==2) && (i%Ten==1|| (i/Ten)%Ten==1|| (i/ -)%Ten==1|| (i/ +)%Ten==1|| (i/10000)%Ten==1|| (i/100000)%Ten==1) ) {sum++;if(i/ +==521|| (i/ -)% +==521|| (i/Ten)% +==521|| i% +==521) k++;} a[0][i]+=sum;a[1][i]+=K;}intm,n,w=0; while(SCANF ("%d%d", &n,&m)! =EOF) printf ("Case %d:%d%d\n", ++w,a[0][m]-a[0][n-1],a[1][m]-a[1][n-1]);}
the most violent of the optimal code
nyoj-about 521