80分qwq,求大佬过目求改
查看原帖
80分qwq,求大佬过目求改
1614236
Wr1te_Bail楼主2024/12/12 12:30
#include <iostream>
#include <cstring>
#include<cmath>
#include<iomanip>
using namespace std;
bool isZhi(int n) {
    int flag = 1;
    if (n == 1)return false;
    if (n % 2 == 0)return false;
    for (int i = 3; i < n / 2; i+=2) {
        if (n % i == 0) {
            flag = 0;
            return false;
            break;
        }
    }
    if (flag)return true;
}

int main() {
    int n;
    cin >> n;
    int a[100];
    for (size_t i = 0; i < n;)
    {
        int x;
        cin >> x;
        if (isZhi(x)) {
            a[i] = x;
            i++;
        }
        else { n -= 1; }
    }
    for (size_t i = 0; i < n; i++)
    {
        cout << a[i] << " ";
    }
    cout << endl;
    return 0;
}

80分qwq,求大佬过目

2024/12/12 12:30
加载中...