首页 > 试题广场 >

整数奇偶排序

[编程题]整数奇偶排序
  • 热度指数:22606 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 64M,其他语言128M
  • 算法知识视频讲解
输入10个整数,彼此以空格分隔。重新排序以后输出(也按空格分隔),要求: 1.先输出其中的奇数,并按从大到小排列; 2.然后输出其中的偶数,并按从小到大排列。

输入描述:
任意排序的10个整数(0~100),彼此以空格分隔。


输出描述:
可能有多组测试数据,对于每组数据,按照要求排序后输出,由空格分隔。

1. 测试数据可能有很多组,请使用while(cin>>a[0]>>a[1]>>...>>a[9])类似的做法来实现;
2. 输入数据随机,有可能相等。
示例1

输入

4 7 3 13 11 12 0 47 34 98

输出

47 13 11 7 3 0 4 12 34 98
头像 LoveJK
发表于 2022-01-15 17:38:27
奇偶不一样的时候先输出奇数,可以在cmp里设置以对2取余递增 #include<iostream> #include<algorithm> using namespace std; bool cmp(int a,int b){ if(a%2==1&&b%2= 展开全文
头像 ii安ii
发表于 2022-02-13 15:41:09
题解 思路:先把所有的按从小到大排序,然后遍历两边数组。第一遍从后往前,遇到奇数就输出;第二遍从前往后,遇到偶数就输出。 #include <iostream> #include <cstdio> #include <algorithm> // http://t 展开全文
头像 渺小小螃蟹
发表于 2021-05-09 13:03:06
#include <iostream> #include <cstdio> #include <algorithm> using namespace std; int arr[10]; bool Compare(int x,int y) { if(x 展开全文
头像 whoway
发表于 2020-12-08 18:05:37
一、单词 odd 奇数even 偶数 二、代码 #include<bits/stdc++.h> using namespace std; int main() { vector<int> solve(10); while( ~scanf("%d",& 展开全文
头像 帅呆呆~
发表于 2022-03-05 14:44:41
#include<iostream> #include<cstdio> #include<algorithm> using namespace std; int arr[10]; bool Compare(int x,int y) { if(x % 2 = 展开全文
头像 semaxcong
发表于 2023-02-12 20:38:26
#include<bits/stdc++.h> using namespace std; bool cmp(int a,int b){ return a>b; } int main(){ vector<int> v1,v2; int i,n 展开全文
头像 立志实干
发表于 2021-02-22 11:08:58
#include <iostream> #include <cstdio> #include <algorithm> using namespace std; const int MAXSIZE = 10; int a[MAXSIZE]; int odd[MA 展开全文
头像 yyer
发表于 2022-12-31 10:23:13
#include <algorithm> #include <iostream> #define maxn 12 using namespace std; int main() { int *A = (int*)malloc(sizeof(int)*(maxn)); 展开全文
头像 牛客557787415号
发表于 2024-05-12 22:17:53
#include<cstdio> #include<algorithm> using namespace std; bool comp (int l, int r) { if (l % 2 != 0 && r % 2 != 0 && 展开全文
头像 易水寒learning
发表于 2022-01-16 18:51:01
#include <iostream> #include <cstdio> #include <algorithm> using namespace std; int arr[10]; bool Compare(int x,int y){ if(x% 展开全文