题解 | #整数奇偶排序#

整数奇偶排序

http://www.nowcoder.com/practice/bbbbf26601b6402c9abfa88de5833163

#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int arr[10];

bool Compare(int x,int y)
{
    if(x%2==1&&y%2==1)
    {
        return y<x;
    }
    else if (x%2==0&&y%2==0)
    {
        return x<y;
    }
    else if (x%2==1&&y%2==0)
    {
        return true;
    }
    else
    {
        return false;
    }
}

int main()
{
    while(scanf("%d",&arr[0])!=EOF)
    {
        for(int i=1;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;
}
全部评论

相关推荐

面向对象的火龙果很爱...:去吃一顿炸鸡就走
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务