80分求助 第三个点说answer too long
查看原帖
80分求助 第三个点说answer too long
1785377
_plp1pigocc楼主2025/7/19 01:07
#include<iostream>
#include<algorithm>
#include<vector>
int main() {
    int n;
    std::cin >> n;
    std::vector<int>s;
    bool flag = false;
    while (!(n == 1 && flag == true)) {
        s.push_back(n);
        if (n % 2 == 1) {
            n = n * 3 + 1;
        }
        else {
            n /= 2;
        }
        if (n == 1) {
            flag = true;
            s.push_back(n);
        }
    }
    int temp=0;
    while (s.size()!=0) {
        temp = *(s.end() - 1);
        s.pop_back();
        std::cout << temp <<" ";
    }
    return 0;
}
2025/7/19 01:07
加载中...