special lucky number

Topic content:
YF doesn't like fame and fortune, so he neither likes 6 nor 8. His lucky numbers are 4 and 7. If a number contains only 4 and 7, he considers that number to be his lucky number.
Now give you two positive integers a, b, and ask to return the number of lucky numbers between a and b, including a and b themselves.
enter description
Enter the number n in the first line, indicating that there are n groups of ab behind
Starting from line 2, each line is a group of ab, separated by spaces.

output description
Each line outputs a number, that is, the number of lucky numbers between a and b.

input sample
3
11 20
4 7
1 10

Sample output
0
2
2

code

/*
Store each digit of the number in an array and compare it
*/

#include <stdio.h>  
int b[100];  
int fun(int a){  
    int m,n,i,j,t=0;b[100];  
    for(n=a,i=0;n!=0;i++){  
        m=n%10;  
        n=n/10;  
        b[i]=m;  
    }  
    for(j=0;j<i;j++){  
        if(b[j]!=4&&b[j]!=7){  
            t = 0;  
            break;  
        }  
        else  
            //t++;  
            t=1;  
    }  
    return t;  
}  
int main(){  
    int x,a,b,sum[100];  
    int i,j;  
    scanf("%d",&x);  
    for(i=0;i<x;i++){  
        scanf("%d%d",&a,&b);  
        sum[i]=0;  
        for(j=a;j<=b;j++){  
            sum[i]+=fun(j);  
        //  printf("%d ",fun(j));  
        }  
    }  
    for(i=0;i<x;i++)  
        printf("%d\n",sum[i]);  
    return 0;  
}  


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325786418&siteId=291194637