参考代码:
#include <iostream> #include <algorithm> #include <vector> using namespace std; bool cmp(int x) //奇偶判断 { if(x%2!=0) return 0; return 1; } bool cmp1(int x,int y) { return x>y; } bool cmp2(int x,int y) { return x<y; } int n = 10; int p[10]; vector<int> vt,vt1; int main() { for(int i=0;i<n;i++) { cin>>p[i]; if(cmp(p[i])==0) vt.push_back(p[i]); else vt1.push_back(p[i]); } sort(vt.begin(),vt.end(),cmp1); sort(vt1.begin(),vt1.end(),cmp2); for(auto i:vt) cout<<i<<" "; for(auto i:vt1) cout<<i<<" "; return 0; }
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题11.1 (C语言代码)浏览:791 |
简单的a+b (C语言代码)浏览:667 |
A+B for Input-Output Practice (IV) (C++代码)浏览:676 |
Pascal三角 (C语言代码)浏览:1183 |
C语言程序设计教程(第三版)课后习题6.7 (C语言代码)浏览:518 |
C语言程序设计教程(第三版)课后习题8.3 (C语言代码)浏览:704 |
字符串的输入输出处理 (C语言代码)浏览:925 |
WU-输出正反三角形 (C++代码)浏览:1018 |
三角形 (C语言代码)浏览:904 |
The 3n + 1 problem (C语言代码)浏览:548 |