Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*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ố.
- Input:
- Dòng đầu tiên ghi lại số tự nhiên T là số lượng bộ test (T<10);
- T dòng kế tiếp mỗi dòng ghi số N (1<N<15).
- Output:
- In ra đáp án theo thứ tự giảm dần.
- Ví dụ:
- Input
- Output
- 2
- 2
- 3
- 88 86 68 66 8 6
- 888 886 868 866 688 686 668 666 88 86 68 66 8 6 */
- #include<bits/stdc++.h>
- using namespace std;
- #define pub push_back
- #define ll long long
- string s[10001];
- vector<string > v ;
- void findThisNumber (int n){
- queue < string > q;
- q.push ("6");
- q.push("8");
- while (1){
- string getFront = q.front ();
- if (getFront.size() > n){
- return ;
- }
- v.pub(getFront);
- string first = getFront + "6";
- string second = getFront + "8";
- q.push ( first );
- q.push( second );
- q.pop();
- }
- }
- int main(){
- int t;
- cin >> t;
- while ( t-- ){
- int n;
- cin >> n;
- findThisNumber(n);
- for (int i=v.size()-1;i>=0;i--){
- cout<<v[i]<<" ";
- }
- cout<<endl;
- v.clear();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment