哪位大佬能帮帮我 哪错了!!!???
2026-04-07 21:12:55
发布于:湖南
代码:
#include <bits/stdc++.h>
using namespace std;
int odd[20];
int main(){
int o=1,e=1;
for(int i=1;i<=10;i++){
int a;
cin>>a;
if(a%2==0){
even[e]=a;
e++;
}else{
odd[o]=a;
o++;
}
}
sort(odd+1,odd+o,greater<int>());
sort(even+1,even+e);
for(int i=1;i<=o-1;i++){
cout<<odd[i]<<" ";
}
for(int i=1;i<=e-1;i++){
cout<<even[i]<<" ";
}
return 0;
}
全部评论 4
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 11;
int a[MAXN];
int evens[MAXN];
int odds[MAXN];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int q = 0, w = 0;
for (int i = 0; i < 10; i++)
{
cin >> a[i];
if (a[i] % 2 == 0) evens[q++] = a[i];
else odds[w++] = a[i];
}
for (int i = 0; i < q - 1; i++)
{
for (int j = 0; j < q - i - 1; j++)
{
if (evens[j] > evens[j + 1])
{
int temp = evens[j];
evens[j] = evens[j + 1];
evens[j + 1] = temp;
}
}
}
for (int i = 0; i < w - 1; i++)
{
for (int j = 0; j < w - i - 1; j++)
{
if (odds[j] < odds[j + 1])
{
int temp = odds[j];
odds[j] = odds[j + 1];
odds[j + 1] = temp;
}
}
}
for (int i = 0; i < w; i++)
{
if (i > 0) cout << " ";
cout << odds[i];
}
for (int i = 0; i < q; i++)
{
cout << " " << evens[i];
}
cout << endl;
return 0;
}2天前 来自 浙江
0


























































































2天前 来自 浙江
0









2天前 来自 浙江
0
2天前 来自 湖南
0









有帮助,赞一个