obq
查看原帖
obq
505424
daybreak2626楼主2021/6/18 10:56
#include<bits/stdc++.h>
using namespace std;
int main()
{   int n;
    cin>>n;
    stack<int> s;

    while(n>1){
        s.push(n);
        if(n&1){
            n = n*3+1;
        }else{
        n = n>>1;
        }
    }
    s.push(1);
    while(!s.empty()){
        cout<<s.top()<<" ";
        s.pop();
    }
    return 0;
}

2021/6/18 10:56
加载中...