题解:sort函数应用之就分别排序
#include<iostream> #include<cstdio> #include<vector> #include<algorithm> using namespace std; bool compare(int lhs,int rhs){ if(lhs%2==1&&rhs%2==0) return 1; else if(lhs%2==0&&rhs%2==0&&lhs<rhs) return 1; else if(lhs%2==1&&rhs%2==1&&lhs>rhs) return 1; else return 0; } int main(){ int arr[20]; for(int i=0;i<10;i++){ scanf("%d",&arr[i]); } sort(arr,arr+10,compare); for(int i=0;i<10;i++){ printf("%d ",arr[i]); } return 0; }
来自acwing 3446题