PAT乙级1005测试点4答案错误,如何解决?(语言-c++)

隔离联系C++,写PAT乙级题目,PAT1005的测试点4一直答案错误
题目:

img

img

我的代码:

#include <iostream>

using namespace std;

typedef struct
{
    int a;
    int num[100] = {0};
    bool flag;
} number;

int fun(int m)
{
    if (m % 2 == 0)
    {
        m = m / 2;
    }
    else
    {
        m = (3 * m + 1) / 2;
    }
    return m;
}
//交换函数,用于排序
void swap(number *stu1, number *stu2)
{
    number stu3;
    stu3 = *stu1;
    *stu1 = *stu2;
    *stu2 = stu3;
}

int main()
{
    //共有x个数
    int x;
    cin >> x;
    number num[x];
    int i, j, k;
    int m, n = 0;
    int o = 0;
    //输入x个数,存在num[i].a中
    for (i = 0; i < x; i++)
    {
        cin >> num[i].a;
        num[i].flag = true;
    }
    //从大到小排序
    for (i = 0; i < x - 1; i++)
    {
        for (j = i; j < x - i - 1; j++)
        {
            if (num[j].a < num[j + 1].a)
            {
                swap(num[j], num[j + 1]);
            }
        }
    }
    //将递推得到的每个数存在num[i].num[j]数组里面
    for (i = 0; i < x; i++)
    {
        j = 0;
        m = fun(num[i].a);
        while (m != 1)
        {
            //大于100的数不输入进num[i].num[j]数组里面
            if (m < 100)
            {
                num[i].num[j] = m;
                j++;
            }
            m = fun(m);
        }
    }
    //三层循环用flag标记关键数
    for (i = 0; i < x; i++)
    {
        for (j = 0; j < x; j++)
        {
            for (k = 0; k < 100; k++)
            {
                if (num[i].a == num[j].num[k])
                {
                    num[i].flag = false;
                }
            }
        }
    }
    //计算共有多少个关键数,用来判断最后一个数不用输出空格
    for (i = 0; i < x; i++)
    {
        if (num[i].flag == true)
        {
            n++;
        }
    }
    //输出结果
    for (i = 0; i < x; i++)
    {
        while (num[i].flag)
        {
            cout << num[i].a;
            o++; //判断是否是最后一个数字
            if (o != n)
            {
                cout << " ";
            }
            break;
        }
    }
    return 0;
}

只有测试点4一直过不了
对(3n+1)大于100的数也进行了排除,还是报错
已经很晚了,实在不行了,代码还没来得及简化,第一次提问,求帮助QAQ
问题网址:https://pintia.cn/problem-sets/994805260223102976/problems/994805320306507776

那得先把1001放出来呢

#include <iostream>
#include <vector>

int main()
{
    const int N = 100;
    int K;
    std::cin >> K;
    std::vector<int> a(K);
    std::vector<int> f(N + 1, 0);
    for (int i = 0; i < K; i++)
    {
        std::cin >> a[i];
        f[a[i]] = 1;
    }

    for (auto x : a)
    {
        while (1)
        {
            if (x == 1)
                break;
            if (x % 2 == 0)
                x /= 2;
            else
                x = 3 * x + 1;
            if (x <= N)
                f[x] = 0;
        }
    }

    for (int i = N, c = 0; i > 1; i--)
    {
        if (f[i])
        {
            if (c > 0)
                std::cout << ' ';
            std::cout << i;
            c++;
        }
    }

    return 0;
}