标题:请问这个对吗?小白求助!!!

这是题目:图片说明

#include <iostream>
using namespace std;
int main()
{
    int a[10];
    bool flag1[10] = { false ,false ,false ,false ,false ,false ,false ,false ,false ,false };
    bool flag2[10] = { false ,false ,false ,false ,false ,false ,false ,false ,false ,false };
    int odd[10] = { 0,0,0,0,0,0,0,0,0,0 }, even[10] = { 0,0,0,0,0,0,0,0,0,0 };
    for (int i = 0; i < 10; i++)
    {
        cin >> a[i];
        if (a[i] % 2 == 0)
        {
            flag1[i] = true;
            even[i] = a[i];
        }
        else
        {
            flag2[i] = true;
            odd[i] = a[i];
        }
    }
    for (int i = 0; i < 10 - 1; i++)
    {
        for (int j = 0; j < 10 - i - 1; j++)
        {
            if (even[j] > even[j + 1] && flag1[j] == true && flag1[j + 1] == true)
            {
                int temp1 = even[j];
                even[j] = even[j + 1];
                even[j + 1] = temp1;
            }
        }
    }
    for (int i = 0; i < 10 - 1; i++)
    {
        for (int j = 0; j < 10 - i - 1; j++)
        {
            if (odd[j] < odd[j + 1] && flag2[j] == true && flag2[j + 1] == true)
            {
                int temp2 = odd[j];
                odd[j] = odd[j + 1];
                odd[j + 1] = temp2;
            }
        }
    }
    for (int i = 0; i < 10; i++)
    {
        if (flag2[i])
        {
            cout << odd[i] << " ";
        }
    }
    for (int i = 0; i < 10; i++)
    {
        if (flag1[i])
        {
            cout << even[i] << " ";
        }
    }
    return 0;
}

请问有问题吗?

查看全部
conniesarah
大国重器2008
2020/05/22 21:53
  • c++
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

1个回复