# Untitled

unknown
c_cpp
2 years ago
2.9 kB
5
Indexable
Never
```#include <iostream>
#define MAX 50
using namespace std;

int S[MAX]; //  solucion

{
for (int i = 0; i < n; i++)
{
do
{
cout << "  Actividad " << i + 1 << endl << endl;
cout << "\tinicio : ";
cin >> c[i];
cout << "\tfinal  : ";
cin >> f[i];
cout << endl;
} while (c[i] > f[i]); // el inicio no puede ser mayor que el final
}
}

void mostrar_datos(int n)
{

cout << "\t\t Ai     :  ";

for (int i = 0; i < n; i++)
cout << i + 1 << ' ';

cout << endl  << "\t\t-------------------------" << endl;

cout << "\t\t inicio :  ";

for (int i = 0; i < n; i++)
cout << c[i] << ' ';

cout << endl;
cout << "\t\t fin    :  ";

for (int i = 0; i < n; i++)
cout << f[i] << ' ';
}

void Ordenar(int n)
{
int aux1, aux2, aux3, band = 1;

for (int i = n - 1; i > 0 && band == 1; i--)
{
band = 0;
for (int j = 0; j < i; j++)
{
if (f[j] > f[j + 1])
{
aux1 = f[j];
f[j] = f[j + 1];
f[j + 1] = aux1;

aux2 = c[j];
c[j] = c[j + 1];
c[j + 1] = aux2;

band = 1;
}
}
}

mostrar_datos(n);
}

void devolver_solucion()
{
cout << endl << " Solucion voraz: \n\n\t";
int i = 0;
while (1)
{
cout << "A" << S[i] + 1 << "";
i++;
if (S[i] == 0)
break;
}
}

void algoritmo_seleccion(int n)
{
Ordenar(n);
int z, k = 1;
S[0] = 0;
z = 0;
for (int i = 1; i < n; i++)
{
if (c[i] >= f[z])
{
z = i;
k++;
}
}
devolver_solucion();
}

void pantalla()
{
cout << endl;
cout << "\t         ----------------------------------------------    " << endl;
cout << "\t                ALGORITMO  SELECCION DE ACTIVIDADES        " << endl;
cout << "\t         ----------------------------------------------    " << endl;
}

int main()
{
system("color 0b");
pantalla();

int N;

cout << "  Ingrese numero de actividades: ";
cin >> N;

cout << endl;