tungggg

solocphat using queue

Mar 18th, 2022
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 KB | None | 0 0
  1. /*Một số được gọi là lộc phát nếu chỉ có 2 chữ số 6 và 8. Cho số tự nhiên N. Hãy liệt kê các số lộc phát có không quá N chữ số.
  2. Input:
  3. Dòng đầu tiên ghi lại số tự nhiên T là số lượng bộ test (T<10);
  4. T dòng kế tiếp mỗi dòng ghi số N (1<N<15).
  5.             Output:
  6. In ra đáp án theo thứ tự giảm dần.
  7.             Ví dụ:
  8. Input
  9. Output
  10. 2
  11. 2
  12. 3
  13. 88 86 68 66 8 6
  14. 888 886 868 866 688 686 668 666 88 86 68 66 8 6 */
  15.  
  16.  
  17.  
  18.  
  19. #include<bits/stdc++.h>
  20. using namespace std;
  21. #define pub push_back
  22. #define ll long long
  23. string s[10001];
  24. vector<string > v ;
  25.  
  26.  
  27. void findThisNumber (int n){
  28.     queue < string > q;
  29.     q.push ("6");
  30.     q.push("8");
  31.     while (1){
  32.         string getFront = q.front ();
  33.        
  34.        
  35.         if (getFront.size() > n){
  36.             return ;
  37.         }
  38.        
  39.         v.pub(getFront);
  40.        
  41.         string first = getFront + "6";
  42.         string second = getFront + "8";
  43.        
  44.         q.push ( first );
  45.         q.push( second );
  46.        
  47.         q.pop();
  48.     }
  49. }
  50.  
  51. int main(){
  52.     int t;
  53.     cin >> t;
  54.     while ( t-- ){
  55.         int n;
  56.         cin >> n;
  57.         findThisNumber(n);
  58.         for (int i=v.size()-1;i>=0;i--){
  59.             cout<<v[i]<<" ";
  60.         }
  61.         cout<<endl;
  62.         v.clear();
  63.     }
  64.     return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment