【打表】HDOJ-2089-不要62

【题目链接:HDOJ-2089

  多组测试数据,所以可以先算出符合条件的所有数保存数组中,输入时则直接遍历数组。

 1 #include<iostream>

 2 #include<cstring>

 3 using namespace std;

 4 int arry[1000001];

 5 int main(){

 6     long n,m,i;

 7     memset(arry,0,sizeof(arry));

 8     //打表 

 9     for(i = 1;i <= 1000001;i++){

10         int temp = i;

11         while(temp > 0){

12             if(temp % 10 == 4 || temp % 100 == 62)

13                 arry[i] = 1;            

14             temp /= 10;

15         }        

16     }

17     while(cin >> n >> m && (n||m)){

18         int ac = m - n + 1;

19         for(i = n;i <= m;i++){

20             if(arry[i] == 1)

21                 ac--;                

22         }

23         cout << ac << endl;

24     }

25     return 0;

26 } 

 

你可能感兴趣的:(OJ)