求助

tctm169 我以逍遥醉人间 2024-08-05 9:21:06 5

#include <bits/stdc++.h> #include #include #include #include #include #include #include #include using namespace std; const int N=10; int c[N]; int a[N],b[N],sum,cnt; int main(){ for(int x=1;x<=N;x++){ cin>>c[x]; if(a[x%2==0]) a[sum]=a[x]; else b[++cnt]=a[x]; } sort(a+1,a+1+sum); sort(b+1,b+1+cnt); for(int k=cnt;k>=1;k--) cout<<b[k]<<" "; for(int k=1;k<=sum;k++) cout<<a[k]<<" ";

}

{{ vote && vote.total.up }}

共 2 条回复

tctm169 我以逍遥醉人间

#include <bits/stdc++.h> #include #include #include #include #include #include #include #include using namespace std; int c[10]; int a[10], b[10], sum=0, cnt=0; int main() { for (int x = 1; x <= 10; x++) { cin >> c[x]; if (a[x % 2 == 0]){ sum++; a[sum] = a[x]; }else{ cnt++; b[cnt] = a[x]; } } sort(a + 1, a + 1 + sum); sort(b + 1, b + 1 + cnt); cout<<sum<<" "<<cnt; for (int k = cnt; k >= 1; k--) cout << b[k] << " "; for (int k = 1; k <= sum; k++) cout << a[k] << " "; } 还是零分

root 站长

a[sum]=a[x]; sum 要自增吧