题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555
数位DP模板题
#include<bits/stdc++.h>
using namespace std;#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)
#define ll long long#define lrt int l,int r,int rt
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define root l,r,rt
#define mst(a,b) memset((a),(b),sizeof(a))
#define pii pair<int,int>
#define fi first
#define se second
#define mk(x,y) make_pair(x,y)
const int mod=1e9+7;
const int maxn=1e2+5;
const int ub=1e6;
ll powmod(ll x,ll y){ll t; for(t=1;y;y>>=1,x=x*x%mod) if(y&1) t=t*x%mod; return t;}
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*
数位Dp模板题
*/
ll f[maxn][10][2],dig[maxn],pos;
ll dfs(int pos,int pre,int fg,int limit){if(pos<0) return fg;if(!limit&&f[pos][pre][fg]!=-1) return f[pos][pre][fg];ll ret=0;int last=limit?dig[pos]:9;rep(i,0,last+1){int ok=(i==9)&&(pre==4);ret+=dfs(pos-1,i,fg||ok,limit&&(i==last));}if(!limit) f[pos][pre][fg]=ret;///return ret;
}
ll n;
int main(){int ca;scanf("%d",&ca);while(ca--){scanf("%lld",&n);rep(i,0,maxn) rep(j,0,10) f[i][j][0]=f[i][j][1]=-1;mst(dig,0),pos=0;while(n) dig[pos++]=n%10,n/=10;printf("%lld\n",dfs(pos-1,0,0,1));}return 0;
}