Friday, April 7, 2017

URI 1259 Problem Solution | Even and odd

URI Online Judge | 1259

Even and Odd

By Neilor Tonin, URI  Brazil
Timelimit: 1
Considering the input of non-negative integer values​​, sort these numbers ​​according to the following criteria: First the even in ascending order followed by the odd in descending order.

Input

The first line of input contains a positive integer number (1 < N < 105). This is the number of following input lines. The next N lines contain, each one, a integer non-negative number.

Output

Print all numbers according to the explanation presented above. Each number must be printed in one line as shown below.
Sample InputSample Output
10
4
32
34
543
3456
654
567
87
6789
98
4
32
34
98
654
3456
6789
567
543
87


URI 1259 Problem Solution in C++

#include <cstdio>
#include <algorithm>
using namespace std;
#define FOR(i, n) for (int i = 0; i < n; ++i)
int par[1000001];
int impar[1000001];
int main()
{
    int n, xp = 0, xi = 0, a;
    scanf("%d", &n);
    FOR(i, n)
    {
        scanf("%d", &a);
        if(a % 2 == 0){
            par[xp] = a;
            xp++;
        }else{
            impar[xi] = a;
            xi++;
        }
    }
    sort(par, par + xp);
    sort(impar, impar + xi);
    FOR(i, xp){printf("%i\n", par[i]);}
    FOR(i, xi){printf("%i\n", impar[xi - i - 1]);}
    return 0;
}

No comments:
Write comments

To know more about the problem, give us your valuable commment. We'll try to help you. Thanks

All rights reserved ©2016 -URI ONLINE JUDGE SOLUTION | Developed by Maniruzzaman Akash

© 2016 URI ONLINE JUDGE SOLUTION. Developed by Maniruzzaman Akash | Distributed By Gooyaabi Templates
Powered by Blogger.