当前位置:网站首页>1181: integer parity sort
1181: integer parity sort
2022-06-28 09:12:00 【A program ape who smashes the keyboard】
1181: Integer parity sorting
The time limit : 1000 ms Memory limit : 65536 KB
Submission number : 21478 Passing number : 13938
【 Title Description 】
Given 10 A sequence of integers , Ask to reorder it . Sorting requirements :
1. Odd number first , Even numbers come after ;
2. Odd numbers are sorted in descending order ;
3. Even numbers are sorted in descending order .
【 Input 】
The input line , contain 10 It's an integer , Separate each other with a space , The range of each integer is greater than or equal to 0, Less than or equal to 30000.
【 Output 】
Sort as required and output a line , Include sorted 10 It's an integer , Numbers are separated by a space .
【 sample input 】
4 7 3 13 11 12 0 47 34 98【 sample output 】
47 13 11 7 3 0 4 12 34 98【 Ideas 】
Put this 10 The number can be sorted into odd and even numbers .
【 a pile 30 Code division 】
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<string>
#include<vector>
using namespace std;
#define for(i,n,m) for(int i=n;i<=m;i++)
const int N=1e5+10;
inline int fread()
{
char ch=getchar();
int n=0,m=1;
while(ch<'0' or ch>'9')
{
if(ch=='-')m=-1;
ch=getchar();
}
while(ch>='0' and ch<='9')n=(n<<3)+(n<<1)+ch-48,ch=getchar();
return n*m;
}
int a[N],b[N],c[N],n,m;
signed main()
{
for(i,1,10)
{
a[i]=fread();
if(a[i]&1)b[++n]=a[i];
else c[++m]=a[i];
}
sort(b+1,b+1+n,greater<int>()),sort(c+1,c+1+n);
for(i,1,n)cout<<b[i]<<" ";
for(i,1,m)cout<<c[i]<<" ";
return 0;
}
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<string>
#include<vector>
using namespace std;
const int N=1e5+10;
inline int fread()
{
char ch=getchar();
int n=0,m=1;
while(ch<'0' or ch>'9')
{
if(ch=='-')m=-1;
ch=getchar();
}
while(ch>='0' and ch<='9')n=(n<<3)+(n<<1)+ch-48,ch=getchar();
return n*m;
}
int a[N],b[N],c[N],n,m;
signed main()
{
for(int i=1;i<=10;i++)
{
a[i]=fread();
if(a[i]&1)b[++n]=a[i];
else c[++m]=a[i];
}
sort(b+1,b+1+n),sort(c+1,c+1+n);
for(int i=n;i>0;i--)cout<<b[i]<<" ";
for(int i=1;i<=m;i++)cout<<c[i]<<" ";
return 0;
}

#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<string>
#include<vector>
using namespace std;
const int N=15;
inline int fread()
{
char ch=getchar();
int n=0,m=1;
while(ch<'0' or ch>'9')
{
if(ch=='-')m=-1;
ch=getchar();
}
while(ch>='0' and ch<='9')n=(n<<3)+(n<<1)+ch-48,ch=getchar();
return n*m;
}
int x,b[N],c[N],n,m;
signed main()
{
for(int i=1;i<=10;i++)
{
x=fread();
if(x&1)b[++n]=x;
else c[++m]=x;
}
sort(b+1,b+1+n),sort(c+1,c+1+n);
for(int i=n;i>0;i--)cout<<b[i]<<" ";
for(int i=1;i<=m;i++)cout<<c[i]<<" ";
return 0;
}

【 Just copy a blog AC Code 】
#include <bits/stdc++.h>
using namespace std;
bool cmpUp(int a, int b)// Ascending
{
return a < b;
}
bool cmpDown(int a, int b)// Descending
{
return a > b;
}
int main()
{
int a, odd[15], even[15], oi = 0, ei = 0;//oi:odd The number of elements in ei:even The number of elements in
for(int i = 1; i <= 10; ++i)
{
cin >> a;
if(a%2 == 0)
even[++ei] = a;// Fill the array
else
odd[++oi] = a;
}
sort(odd+1, odd+1+oi, cmpDown);// Odd descending sort
sort(even+1, even+1+ei, cmpUp);// Even ascending sort
for(int i = 1; i <= oi; ++i)
cout << odd[i] << ' ';
for(int i = 1; i <= ei; ++i)
cout << even[i] << ' ';
return 0;
}

【 Another pile of debugging 30 Code division 】
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<string>
#include<vector>
using namespace std;
const int N=1e5+10;
inline int fread()
{
char ch=getchar();
int n=0,m=1;
while(ch<'0' or ch>'9')
{
if(ch=='-')m=-1;
ch=getchar();
}
while(ch>='0' and ch<='9')n=(n<<3)+(n<<1)+ch-48,ch=getchar();
return n*m;
}
int a[N],b[N],c[N],n,m;
signed main()
{
for(int i=1;i<=10;i++)
{
a[i]=fread();
if(a[i]&1)b[++n]=a[i];
else c[++m]=a[i];
}
sort(b+1,b+1+n),sort(c+1,c+1+n);
for(int i=n;i>0;i--)cout<<b[i]<<' ';
for(int i=1;i<=m;i++)cout<<c[i]<<' ';
return 0;
}

#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<string>
#include<vector>
using namespace std;
const int N=15;
inline int fread()
{
char ch=getchar();
int n=0,m=1;
while(ch<'0' or ch>'9')
{
if(ch=='-')m=-1;
ch=getchar();
}
while(ch>='0' and ch<='9')n=(n<<3)+(n<<1)+ch-48,ch=getchar();
return n*m;
}
int a[N],b[N],c[N],n,m;
signed main()
{
for(int i=1;i<=10;i++)
{
a[i]=fread();
if(a[i]&1)b[++n]=a[i];
else c[++m]=a[i];
}
sort(b+1,b+1+n),sort(c+1,c+1+n);
for(int i=n;i>0;i--)cout<<b[i]<<" ";
for(int i=1;i<=m;i++)cout<<c[i]<<" ";
return 0;
}

#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<string>
#include<vector>
using namespace std;
const int N=1e5+10;
inline int fread()
{
char ch=getchar();
int n=0,m=1;
while(ch<'0' or ch>'9')
{
if(ch=='-')m=-1;
ch=getchar();
}
while(ch>='0' and ch<='9')n=(n<<3)+(n<<1)+ch-48,ch=getchar();
return n*m;
}
int a[N],b[N],c[N],n=0,m=0;
signed main()
{
for(int i=1;i<=10;i++)
{
a[i]=fread();
if(a[i]&1)b[++n]=a[i];
else c[++m]=a[i];
}
sort(b+1,b+1+n),sort(c+1,c+1+n);
for(int i=n;i>0;i--)cout<<b[i]<<" ";
for(int i=1;i<=m;i++)cout<<c[i]<<" ";
return 0;
}

#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<string>
#include<vector>
using namespace std;
const int N=1e5+10;
inline int fread()
{
char ch=getchar();
int n=0,m=1;
while(ch<'0' or ch>'9')
{
if(ch=='-')m=-1;
ch=getchar();
}
while(ch>='0' and ch<='9')n=(n<<3)+(n<<1)+ch-48,ch=getchar();
return n*m;
}
int a[N],b[N],c[N],n,m;
bool cmp(int n,int m)
{
return n>m;
}
signed main()
{
for(int i=1;i<=10;i++)
{
a[i]=fread();
if(a[i]&1)b[++n]=a[i];
else c[++m]=a[i];
}
sort(b+1,b+1+n,cmp),sort(c+1,c+1+n);
for(int i=1;i<=n;i++)cout<<b[i]<<" ";
for(int i=1;i<=m;i++)cout<<c[i]<<" ";
return 0;
}

#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<string>
#include<vector>
using namespace std;
const int N=1e5+10;
inline int fread()
{
char ch=getchar();
int n=0,m=1;
while(ch<'0' or ch>'9')
{
if(ch=='-')m=-1;
ch=getchar();
}
while(ch>='0' and ch<='9')n=(n<<3)+(n<<1)+ch-48,ch=getchar();
return n*m;
}
int a[N],b[N],c[N],n,m;
signed main()
{
for(int i=1;i<=10;i++)
{
a[i]=fread();
if(a[i]&1)b[++n]=a[i];
else c[++m]=a[i];
}
sort(b+1,b+1+n),sort(c+1,c+1+n);
for(int i=n;i>=1;i--)cout<<b[i]<<" ";
for(int i=1;i<=m;i++)cout<<c[i]<<" ";
return 0;
}

#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<string>
#include<vector>
using namespace std;
const int N=1e5+10;
inline int fread()
{
char ch=getchar();
int n=0,m=1;
while(ch<'0' or ch>'9')
{
if(ch=='-')m=-1;
ch=getchar();
}
while(ch>='0' and ch<='9')n=(n<<3)+(n<<1)+ch-48,ch=getchar();
return n*m;
}
int a[N],b[N],c[N],n,m;
signed main()
{
for(int i=1;i<=10;i++)
{
a[i]=fread();
if(a[i]%2==0)b[++n]=a[i];
else c[++m]=a[i];
}
sort(b+1,b+1+n),sort(c+1,c+1+n);
for(int i=n;i>0;i--)cout<<c[i]<<" ";
for(int i=1;i<=m;i++)cout<<b[i]<<" ";
return 0;
}

#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<string>
#include<vector>
using namespace std;
const int N=1e5+10;
inline int fread()
{
char ch=getchar();
int n=0,m=1;
while(ch<'0' or ch>'9')
{
if(ch=='-')m=-1;
ch=getchar();
}
while(ch>='0' and ch<='9')n=(n<<3)+(n<<1)+ch-48,ch=getchar();
return n*m;
}
int a[N],b[N],c[N],n,m;
signed main()
{
for(int i=1;i<=10;i++)
{
a[i]=fread();
if(a[i]%2==0)b[++n]=a[i];
else c[++m]=a[i];
}
sort(b+1,b+1+n),sort(c+1,c+1+n);
for(int i=n;i>0;i--)cout<<c[i]<<" ";
for(int i=1;i<=m;i++)cout<<b[i]<<" ";
return 0;
}

#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<string>
#include<vector>
using namespace std;
const int N=1e5+10;
inline int fread()
{
char ch=getchar();
int n=0,m=1;
while(ch<'0' or ch>'9')
{
if(ch=='-')m=-1;
ch=getchar();
}
while(ch>='0' and ch<='9')n=(n<<3)+(n<<1)+ch-48,ch=getchar();
return n*m;
}
int a[N],b[N],c[N],n,m;
signed main()
{
for(int i=1;i<=10;i++)
{
a[i]=fread();
if(a[i]%2==0)b[++n]=a[i];
else c[++m]=a[i];
}
sort(b+1,b+1+n),sort(c+1,c+1+m);
for(int i=n;i>0;i--)cout<<c[i]<<" ";
for(int i=1;i<=m;i++)cout<<b[i]<<" ";
return 0;
}

【AC Code 】
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<string>
#include<vector>
using namespace std;
const int N=1e5+10;
inline int fread()
{
char ch=getchar();
int n=0,m=1;
while(ch<'0' or ch>'9')
{
if(ch=='-')m=-1;
ch=getchar();
}
while(ch>='0' and ch<='9')n=(n<<3)+(n<<1)+ch-48,ch=getchar();
return n*m;
}
int a[N],b[N],c[N],n,m;
signed main()
{
for(int i=1;i<=10;i++)
{
a[i]=fread();
if(a[i]&1)b[++n]=a[i];// Odd number
else c[++m]=a[i];// even numbers
}
sort(b+1,b+1+n),sort(c+1,c+1+m/* Slide the handle before m It has been written. n That led to so many WA*/);// Sort separately
for(int i=n;i>0;i--)cout<<b[i]<<" ";
for(int i=1;i<=m;i++)cout<<c[i]<<" ";
return 0;
}
边栏推荐
- containerd1.5.5的安装
- Assertions used in the interface automation platform
- RMAN backup message ora-19809 ora-19804
- SQL injection file read / write
- 玩玩sftp上传文件
- [big case] Xuecheng online website
- 手机炒股开户安不安全?
- How to solve the problem of port number occupation
- How to implement two factor authentication MFA based on RADIUS protocol?
- Application of energy management system in iron and steel enterprises
猜你喜欢
随机推荐
分而治之之经典Hanoi
Chrome devtools
1182: effets de la photo de groupe
STL - inverter
Stock suspension
电子元器件销售ERP管理系统哪个比较好?
自动转换之-面试题
Applet: traverse the value of an array in the list, which is equivalent to for= "list" list An item in comment
SQL注入之文件读写
买卖股票费用计算
Fire fighting work and measures in Higher Vocational Colleges
Using transform:scale causes the page mouse hover event to disappear
Ffmpeg streaming fails to update header with correct duration
Boundary value analysis method for learning basic content of software testing (2)
Learn how Alibaba manages the data indicator system
Divide and rule classic Hanoi
How to implement two factor authentication MFA based on RADIUS protocol?
1182:合影效果
"Jianzhi offer" -- Interview Question 4: finding two-dimensional arrays
Basic content learning of software testing (I)









