URI Online Judge Solution 1252 - Data Structure | 1252 - Sort sort and sort - Online Judge Solution

Latest

It is a free Online judges problems solution list. Here you can find UVA online Judge Solution, URI Online Judge Solution, Code Marshal Online Judge Solution, Spoz Online Judge Problems Solution

Saturday, May 11, 2019

URI Online Judge Solution 1252 - Data Structure | 1252 - Sort sort and sort

URI Online Judge Solution Data Structure | 1252 - Sort sort and sort

URI Online Judge Solution SQL | 1252 Sort sort and sort  | Beginner

Problem Name: Data Structure | Sort sort and sort
Problem Number : URI - Data Structure | 1252 Sort sort and sort
Online Judge : URI Online Judge Solution
Category: Data Structure
Solution Language : Data Structure



URI Online Judge Solution 1252 - Data Structure | 1252 - Sort sort and sort: Using C++


#include<bits/stdc++.h>
using namespace std;
int m;
bool comp (int a, int b){
    if (b%m == a%m)
        if(abs(a)%2 ==abs(b)%2){
            if (a%2 != 0){
                return a > b;
            }else{ 
                return b > a;
            }
        }
        return abs(a)%2 > abs(b)%2; 
    }
    return a%m < b%m;
}
int main()
{
    int n;
 
    while(cin>>n>>m&&n&&m){
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n,comp);
    cout<<n<<" "<<m<<endl;
    for(int i=0;i<n;i++)
        cout<<a[i]<<endl;
    }
    printf("0 0n");
}


URI Online Judge Solution 1252 - Data Structure | 1252 - Sort sort and sort: Using C Language


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <algorithm>

using namespace std;

int M;


bool comp (int a, int b){
    if (b%M == a%M){ /// retorna primeiro os impares e depois os pares;
        if(abs(a)%2 ==abs(b)%2){ ///comparando dois pares ou dois impares
            if (a%2 != 0){ ///impares
                return a > b;
            }else{ ///a e b s?o pares
                return b > a;
            }
        }
        return abs(a)%2 > abs(b)%2; /// impares antes dos pares
    }
    return a%M < b%M;
}

int main()
{
	int N, cont;

	scanf("%d", &N);
	scanf("%d", &M);

	while(N!=0 && M!=0)
	{
		int vetor[N];
		printf("%d %d\n", N, M);

		for(cont=0;cont<N;cont++){
			scanf("%d", &vetor[cont]);
		}

		sort(vetor,vetor+N,comp);

		for(cont=0;cont<N;cont++){
			printf("%d\n", vetor[cont]);
		}

		scanf("%d", &N);
		scanf("%d", &M);

	}
	printf("0 0\n");

	return 0;
}

Demonstration:


Tags: URI Online Judge Solution, URI OJ Solution list, URI Problems Solution, URI solver, URI all problem solution list, URI SQL |URI Online Judge Solution 1252 - Data Structure | 1252 - Sort sort and sort, URI 1252 URI Online Judge Solution 1252 - Data Structure | 1252 - Sort sort and sort

1 comment:

  1. do you just copy paste the solution from another blog or github? don't you solve it by yourself? i have found the exact same solution with the same comments (written in another human language) that has been published about 4 years ago obviously before publishing your solution.

    ReplyDelete