问栈的实现方法
查看原帖
问栈的实现方法
1041765
AKkkk_TIX楼主2024/8/9 13:04

我用的栈,tmd前三个测试点RE,后两个WA,dalao帮忙看看

#include <bits/stdc++.h>
using namespace std;
stack<int> st;
int n, tmp;
int main(){
    cin >> n;
    tmp = n;
    while(n != 1){
        if(n % 2 == 0){
            n /= 2;
            st.push(n);
        }
        else{
            n *= 3;
            n++;
            st.push(n);
        }
    }
    
    for(int i = 0;i < tmp;i++){
        cout << st.top();
        st.pop();
    }
    
    return 0;
}

记录详情

2024/8/9 13:04
加载中...