█████████ ████ ███░░░░░███ ░░███ ███ ░░░ ██████ ███████ ██████ ██████ ░███ ███░░███ ███░░███ ███░░███ ███░░███ ░███ ░███ ░███░███ ░███ ░███████ ░███ ░███ ░░███ ███░███ ░███░███ ░███ ░███░░░ ░███ ░███ ░░█████████ ░░██████ ░░████████░░██████ ░░██████ ░░░░░░░░░ ░░░░░░ ░░░░░░░░ ░░░░░░ ░░░░░░

Envío 5322

Problema 0xde - Ordenar un arreglo grande

  • Autor: tille
  • Fecha: 2021-11-08 23:50:11 UTC (Hace alrededor de 3 años)
Caso # Resultado Tiempo Memoria
#1
Error de compilación
                      main.c:1:1: error: unknown type name 'Quicksort'
Quicksort example program in c++:
^
main.c:1:18: error: expected ';' after top level declarator
Quicksort example program in c++:
                 ^
                 ;
main.c:2:9: fatal error: 'iostream' file not found
#include<iostream>
        ^~~~~~~~~~
3 errors generated.

                    
#2
Error de compilación
                      main.c:1:1: error: unknown type name 'Quicksort'
Quicksort example program in c++:
^
main.c:1:18: error: expected ';' after top level declarator
Quicksort example program in c++:
                 ^
                 ;
main.c:2:9: fatal error: 'iostream' file not found
#include<iostream>
        ^~~~~~~~~~
3 errors generated.

                    
#3
Error de compilación
                      main.c:1:1: error: unknown type name 'Quicksort'
Quicksort example program in c++:
^
main.c:1:18: error: expected ';' after top level declarator
Quicksort example program in c++:
                 ^
                 ;
main.c:2:9: fatal error: 'iostream' file not found
#include<iostream>
        ^~~~~~~~~~
3 errors generated.

                    
#4
Error de compilación
                      main.c:1:1: error: unknown type name 'Quicksort'
Quicksort example program in c++:
^
main.c:1:18: error: expected ';' after top level declarator
Quicksort example program in c++:
                 ^
                 ;
main.c:2:9: fatal error: 'iostream' file not found
#include<iostream>
        ^~~~~~~~~~
3 errors generated.

                    
#5
Error de compilación
                      main.c:1:1: error: unknown type name 'Quicksort'
Quicksort example program in c++:
^
main.c:1:18: error: expected ';' after top level declarator
Quicksort example program in c++:
                 ^
                 ;
main.c:2:9: fatal error: 'iostream' file not found
#include<iostream>
        ^~~~~~~~~~
3 errors generated.

                    
#6
Error de compilación
                      main.c:1:1: error: unknown type name 'Quicksort'
Quicksort example program in c++:
^
main.c:1:18: error: expected ';' after top level declarator
Quicksort example program in c++:
                 ^
                 ;
main.c:2:9: fatal error: 'iostream' file not found
#include<iostream>
        ^~~~~~~~~~
3 errors generated.

                    
#7
Error de compilación
                      main.c:1:1: error: unknown type name 'Quicksort'
Quicksort example program in c++:
^
main.c:1:18: error: expected ';' after top level declarator
Quicksort example program in c++:
                 ^
                 ;
main.c:2:9: fatal error: 'iostream' file not found
#include<iostream>
        ^~~~~~~~~~
3 errors generated.

                    
#8
Error de compilación
                      main.c:1:1: error: unknown type name 'Quicksort'
Quicksort example program in c++:
^
main.c:1:18: error: expected ';' after top level declarator
Quicksort example program in c++:
                 ^
                 ;
main.c:2:9: fatal error: 'iostream' file not found
#include<iostream>
        ^~~~~~~~~~
3 errors generated.

                    
#9
Error de compilación
                      main.c:1:1: error: unknown type name 'Quicksort'
Quicksort example program in c++:
^
main.c:1:18: error: expected ';' after top level declarator
Quicksort example program in c++:
                 ^
                 ;
main.c:2:9: fatal error: 'iostream' file not found
#include<iostream>
        ^~~~~~~~~~
3 errors generated.

                    
#10
Error de compilación
                      main.c:1:1: error: unknown type name 'Quicksort'
Quicksort example program in c++:
^
main.c:1:18: error: expected ';' after top level declarator
Quicksort example program in c++:
                 ^
                 ;
main.c:2:9: fatal error: 'iostream' file not found
#include<iostream>
        ^~~~~~~~~~
3 errors generated.

                    
#11
Error de compilación
                      main.c:1:1: error: unknown type name 'Quicksort'
Quicksort example program in c++:
^
main.c:1:18: error: expected ';' after top level declarator
Quicksort example program in c++:
                 ^
                 ;
main.c:2:9: fatal error: 'iostream' file not found
#include<iostream>
        ^~~~~~~~~~
3 errors generated.

                    
#12
Error de compilación
                      main.c:1:1: error: unknown type name 'Quicksort'
Quicksort example program in c++:
^
main.c:1:18: error: expected ';' after top level declarator
Quicksort example program in c++:
                 ^
                 ;
main.c:2:9: fatal error: 'iostream' file not found
#include<iostream>
        ^~~~~~~~~~
3 errors generated.

                    
#13
Error de compilación
                      main.c:1:1: error: unknown type name 'Quicksort'
Quicksort example program in c++:
^
main.c:1:18: error: expected ';' after top level declarator
Quicksort example program in c++:
                 ^
                 ;
main.c:2:9: fatal error: 'iostream' file not found
#include<iostream>
        ^~~~~~~~~~
3 errors generated.

                    
#14
Error de compilación
                      main.c:1:1: error: unknown type name 'Quicksort'
Quicksort example program in c++:
^
main.c:1:18: error: expected ';' after top level declarator
Quicksort example program in c++:
                 ^
                 ;
main.c:2:9: fatal error: 'iostream' file not found
#include<iostream>
        ^~~~~~~~~~
3 errors generated.

                    
#15
Error de compilación
                      main.c:1:1: error: unknown type name 'Quicksort'
Quicksort example program in c++:
^
main.c:1:18: error: expected ';' after top level declarator
Quicksort example program in c++:
                 ^
                 ;
main.c:2:9: fatal error: 'iostream' file not found
#include<iostream>
        ^~~~~~~~~~
3 errors generated.

                    
#16
Error de compilación
                      main.c:1:1: error: unknown type name 'Quicksort'
Quicksort example program in c++:
^
main.c:1:18: error: expected ';' after top level declarator
Quicksort example program in c++:
                 ^
                 ;
main.c:2:9: fatal error: 'iostream' file not found
#include<iostream>
        ^~~~~~~~~~
3 errors generated.

                    
#17
Error de compilación
                      main.c:1:1: error: unknown type name 'Quicksort'
Quicksort example program in c++:
^
main.c:1:18: error: expected ';' after top level declarator
Quicksort example program in c++:
                 ^
                 ;
main.c:2:9: fatal error: 'iostream' file not found
#include<iostream>
        ^~~~~~~~~~
3 errors generated.

                    
#18
Error de compilación
                      main.c:1:1: error: unknown type name 'Quicksort'
Quicksort example program in c++:
^
main.c:1:18: error: expected ';' after top level declarator
Quicksort example program in c++:
                 ^
                 ;
main.c:2:9: fatal error: 'iostream' file not found
#include<iostream>
        ^~~~~~~~~~
3 errors generated.

                    
#19
Error de compilación
                      main.c:1:1: error: unknown type name 'Quicksort'
Quicksort example program in c++:
^
main.c:1:18: error: expected ';' after top level declarator
Quicksort example program in c++:
                 ^
                 ;
main.c:2:9: fatal error: 'iostream' file not found
#include<iostream>
        ^~~~~~~~~~
3 errors generated.

                    
#20
Error de compilación
                      main.c:1:1: error: unknown type name 'Quicksort'
Quicksort example program in c++:
^
main.c:1:18: error: expected ';' after top level declarator
Quicksort example program in c++:
                 ^
                 ;
main.c:2:9: fatal error: 'iostream' file not found
#include<iostream>
        ^~~~~~~~~~
3 errors generated.

                    
#21
Error de compilación
                      main.c:1:1: error: unknown type name 'Quicksort'
Quicksort example program in c++:
^
main.c:1:18: error: expected ';' after top level declarator
Quicksort example program in c++:
                 ^
                 ;
main.c:2:9: fatal error: 'iostream' file not found
#include<iostream>
        ^~~~~~~~~~
3 errors generated.

                    
#22
Error de compilación
                      main.c:1:1: error: unknown type name 'Quicksort'
Quicksort example program in c++:
^
main.c:1:18: error: expected ';' after top level declarator
Quicksort example program in c++:
                 ^
                 ;
main.c:2:9: fatal error: 'iostream' file not found
#include<iostream>
        ^~~~~~~~~~
3 errors generated.

                    
#23
Error de compilación
                      main.c:1:1: error: unknown type name 'Quicksort'
Quicksort example program in c++:
^
main.c:1:18: error: expected ';' after top level declarator
Quicksort example program in c++:
                 ^
                 ;
main.c:2:9: fatal error: 'iostream' file not found
#include<iostream>
        ^~~~~~~~~~
3 errors generated.

                    
#24
Error de compilación
                      main.c:1:1: error: unknown type name 'Quicksort'
Quicksort example program in c++:
^
main.c:1:18: error: expected ';' after top level declarator
Quicksort example program in c++:
                 ^
                 ;
main.c:2:9: fatal error: 'iostream' file not found
#include<iostream>
        ^~~~~~~~~~
3 errors generated.

                    
#25
Error de compilación
                      main.c:1:1: error: unknown type name 'Quicksort'
Quicksort example program in c++:
^
main.c:1:18: error: expected ';' after top level declarator
Quicksort example program in c++:
                 ^
                 ;
main.c:2:9: fatal error: 'iostream' file not found
#include<iostream>
        ^~~~~~~~~~
3 errors generated.

                    
#26
Error de compilación
                      main.c:1:1: error: unknown type name 'Quicksort'
Quicksort example program in c++:
^
main.c:1:18: error: expected ';' after top level declarator
Quicksort example program in c++:
                 ^
                 ;
main.c:2:9: fatal error: 'iostream' file not found
#include<iostream>
        ^~~~~~~~~~
3 errors generated.

                    
#27
Error de compilación
                      main.c:1:1: error: unknown type name 'Quicksort'
Quicksort example program in c++:
^
main.c:1:18: error: expected ';' after top level declarator
Quicksort example program in c++:
                 ^
                 ;
main.c:2:9: fatal error: 'iostream' file not found
#include<iostream>
        ^~~~~~~~~~
3 errors generated.

                    
Puntos totales: 0 / 100

Código

Quicksort example program in c++:
#include<iostream>
#include<cstdlib>
 
using namespace std;
 
// Swapping two values.
void swap(int *a, int *b)
{
	int temp; 
	temp = *a;
	*a = *b;
	*b = temp;
}
 
// Partitioning the array on the basis of values at high as pivot value.
int Partition(int a[], int low, int high)
{
	int pivot, index, i;
	index = low;
	pivot = high;
 
	// Getting index of the pivot.
	for(i=low; i < high; i++)
	{
		if(a[i] < a[pivot])
		{
			swap(&a[i], &a[index]);
			index++;
		}
	}
	// Swapping value at high and at the index obtained.
	swap(&a[pivot], &a[index]);
 
	return index;
}
 
// Random selection of pivot.
int RandomPivotPartition(int a[], int low, int high)
{
	int pvt, n, temp;
	n = rand();
	// Randomizing the pivot value in the given subpart of array.
	pvt = low + n%(high-low+1);
 
	// Swapping pivot value from high, so pivot value will be taken as a pivot while partitioning.
	swap(&a[high], &a[pvt]);
 
	return Partition(a, low, high);
}
 
int QuickSort(int a[], int low, int high)
{
	int pindex;
	if(low < high)
	{
		// Partitioning array using randomized pivot.
		pindex = RandomPivotPartition(a, low, high);
		// Recursively implementing QuickSort.
		QuickSort(a, low, pindex-1);
		QuickSort(a, pindex+1, high);
	}
	return 0;
}
 
int main()
{
	int n, i;
	cin>>n;
 
	int arr[n];
	for(i = 0; i < n; i++)
	{
		cin>>arr[i];
	}
 
	QuickSort(arr, 0, n-1);
 
	for (i = 0; i < n; i++)
        	cout<< arr[i] << " ";
    cout << endl;
 
	return 0;
}