3 条题解
-
1
依然速度最快
#include<cstdio> #include<algorithm> using namespace std; bool cmp(int a,int b){ return a>b; } int main(){ int a[15],b[15],c[15],cnt1=0,cnt2=0; for(int i=1;i<=10;i++){ scanf("%d",&a[i]); if(a[i]%2==1) b[++cnt1]=a[i]; else c[++cnt2]=a[i]; } sort(b+1,b+cnt1+1,cmp); sort(c+1,c+cnt2+1); for(int i=1;i<=cnt1;i++) printf("%d ",b[i]); for(int i=1;i<=cnt2;i++) printf("%d ",c[i]); return 0; }
-
1
yasuo👀️
#include <iostream> #include <algorithm> bool yasuo(int a,int b){ if(a%2!=b%2) return a%2==1&&b%2==0; else{ if(a%2==1) return a>b; else return a<b;}} int main(){ int q[10]; for(int i=0;i<10;i++) std::cin>>q[i]; std::sort(q,q+10,yasuo); for(int i=0;i<10;i++) std::cout<<q[i]<<" "; return 0;}
-
1
#include <bits/stdc++.h> using namespace std; int main() { int j[15],o[15],jj=0,oo=0; for (int i=1;i<=10;i++){ int a; cin>>a; if (a%2!=0){ j[jj+1]=a; jj++; } else{ o[oo+1]=a; oo++; } } sort(j+1,j+jj+1); sort(o+1,o+oo+1); for (int i=jj;i>=1;i--) cout<<j[i]<<" "; for (int i=1;i<=oo;i++) cout<<o[i]<<" "; }//没有什么很屌的算法,人脑怎么完成这个要求的,我代码怎么写
- 1
信息
- ID
- 405
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 4
- 标签
- 递交数
- 19
- 已通过
- 15
- 上传者