文章

17

粉丝

0

获赞

119

访问

4.6k

头像
排序 题解:
P1010 兰州大学/贵州大学机试
发布于2025年2月28日 17:36
阅读数 224

#include <bits/stdc++.h>
using namespace std;

bool compare(const int& n1,const int& n2){
    if((n1%2==1)&&(n2%2==0)) return true;
    else if((n1%2==0)&&(n2%2==1)) return false;
    else return n1<n2;
}
    
int main() {
    int n;
    cin>>n;
    int s[1000];
    for(int i=0;i<n;i++)
    scanf("%d",&s[i]);
    sort(s,s+n,compare);
    for(int i=0;i<n;i++) cout<<s[i]<<" ";
    return 0;
}
 

 

1.写比较函数要注意只用写特殊情况

2.输入时scanf不用在意空格 要循环输入

3.true false不要打错

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发