当前位置:网站首页>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;
}
边栏推荐
- Data mining modeling practice
- 1182: group photo effect
- Is it safe to open an account for mobile phone stock speculation?
- DEJA_ Vu3d - 052 of cesium feature set - Simulation of satellite orbit (high altitude) effect
- rman备份报ORA-19809 ORA-19804
- How to solve the problem of high concurrency and seckill
- Application of energy management system in iron and steel enterprises
- Boundary value analysis method for learning basic content of software testing (2)
- Find the total number of 1 appearing in the integer 1-N and the number of 1 in the binary of the integer
- Matlab tips (20) matrix analysis -- principal component regression
猜你喜欢

Installation of containerd1.5.5

图解MySQL的binlog、redo log和undo log

Loggerfactory uses log4j Parameter introduction of properties

From knowledge to wisdom: how far will the knowledge map go?

104. maximum depth of binary tree

1182:合影效果

redis5.0的槽点迁移,随意玩(单机迁移集群)

SQL injection file read / write

DEJA_VU3D - Cesium功能集 之 051-地形开挖完美实现

spark的资源调度和任务调度
随机推荐
中金财富开户安全吗?怎么收费?
从知识到智慧:知识图谱还要走多远?
Zhejiang energy online monitoring and management system
Installation of containerd1.5.5
Prototype chain JS
硬盘基本知识(磁头、磁道、扇区、柱面)
State machine program framework
Discussion on the improvement and application of the prepayment system in the management of electricity charge and price
为什么SELECT * 会导致查询效率低?
Chrome devtools
Loggerfactory uses log4j Parameter introduction of properties
1. Kimball dimension modeling of data warehouse: what is a fact table?
Apache Doris 成为 Apache 顶级项目
Error: `brew cask` is no longer a `brew` command. Use `brew <command> --cask` instead.
How to solve the problem of port number occupation
Test cases for learning the basic content of software testing (II)
Fire safety hazards
Goldbach`s Conjecture
1182: effets de la photo de groupe
Common test method used by testers --- orthogonal method