You are on page 1of 10

//#include <iostream>

// // #include<cstdlib.h>
//#include<ctime>
//#include<conio.h>
//
//
//using namespace std;

// void calcule(int v[20],int n)


//{
// int max;
//// srand(time(NULL));
// for(int I=1;I<=n;I++)
// if(v[I]>max)
// max=v[I];
//}
//int main()
//{int a[20],nr;
// nr=5;
//for(int k=1;k<=nr;k++)
// a[k]=k;
//calcule(a,nr);
//for(int k=1;k<=nr;k++)
// cout<<a[k]<<" "; //afiseaza 2 4 6 8 10
//return 0;
//}

// #include <pch.h>
#include <iostream>
#include <cstdlib>
#include <ctime>
#define n 20
// #define n 15

using namespace std;

//int generator(int *max)


//{
// int v[num];
//
//
// return 0;
//}

int main()
{
clock_t t_start, t_stop;
float seconds;
t_start = clock();

int v[n];

srand(time(NULL));
for (int i = 0; i < n; i++)
{
v[n] = rand();
cout << v[n] << '\t';

int max = -9999;

for (int i = 0; i < n; i++)


{
if (v[n] > max)
max = v[n];
max++;
}
cout <<"\n"<< "numar maxim" << " " << max << endl;

max = v[0];
// int i=0;
for (int i = 0; i < n; i++)
{
if (v[n] == max)
// v[n]=max;
cout<<endl<<"introdu pozitia="<<" ";
cin >> i;
cout << "maximul depe pozitia "<<i<<" este=" << max<<endl;

t_stop = clock();
seconds = ((float)(t_stop - t_start)) / CLOCKS_PER_SEC;

cout <<endl<<"timp de executie:"<<" "<< seconds<<"s"<<endl;

return 0;
}
#include<iostream>

using namespace std;

int a[25], b[25], c[25], n, i, j;

int main()

cout << "nr de elemente = "; cin >> n;

for (i = 0; i < n; i++)


{ cout << "v["<< i << "] = "; cin >> a[i]; }

for (i = 0; i < n; i++) cout << a[i] << " ";

// Sortarea prin numarare


// Pasul 1 fac o copie a vectorului a in vectorul c

for (i = 0; i < n; i++)

c[i] = a[i];

// Pas 2 crearea vectorului b[i]

// determinam pentru fiecare element cate elemente sunt mai mici

for (i = 0; i < n; i++)

for (j = i + 1; j < n; j++)

if (a[i] > a[j])

b[j]++;

else b[i]++;

// Pasul 3 Se rescriu elementele lui a in ordine crescatoare

for (i = 0; i < n; i++)

a[b[i]] = c[i];

cout << endl;

// Afisarea vectorului sortat

for (i = 0; i < n; i++) cout << a[i] << " ";


cout << endl << "element de pe pozitia= ";
cin >> i;
cout << a[i-1];

return 0;
}

//#include <iostream>
// // #include<cstdlib.h>
//#include<ctime>
//#include<conio.h>
//
//
//using namespace std;
//
// void calcule(int v[20],int n)
//{
// int max;
//// srand(time(NULL));
// for(int I=1;I<=n;I++)
// if(v[I]>max)
// max=v[I];
//}
//int main()
//{int a[20],nr;
// nr=5;
//for(int k=1;k<=nr;k++)
// a[k]=k;
//calcule(a,nr);
//for(int k=1;k<=nr;k++)
// cout<<a[k]<<" "; //afiseaza 2 4 6 8 10
//return 0;
//}
//#include <iostream>
// #include <conio.h>
// // #include <stdlib.h>
//#include <math.h>
//#define n 30
// using namespace std;

//
//void lin_sort(int* a, int n)
//
//{
// int b[dimmax1] = { 0 }, c[dimmax1], i, j;
//
// //elementele vectorului a sunt salvate in c
//
// for (i = 0; i < n; i++) c[i] = a[i];
//
// // determinam pentru fiecare element cate elemente sunt mai mici
//
// for (i = 0; i < n; i++)
//
// for (j = i + 1; j < n; j++)
//
// if (a[i] < a[j]) b[j]++;
//
// else b[i]++;
//
// // se rescriu elementele lui a in ordine crescatoare
//
// for (i = 0; i < n; i++) a[b[i]] = c[i];
//
//}
//int main()
//{
// int a[n];
// liniar(&a, n);
// for (int i = 0; i < n; i++)
// {
// cout << a[i] << " ";
//
// }
// return 0;
//}

//#include<iostream>
//#include<ctime>
//#include <cstdlib>
//#include<conio.h>
//#define DMAX 20
// #define n 20
//
//using namespace std;
//
//using std::cin;
//using std::cout;
//
//int n;
//int frq[DMAX];
//
//int main() {
// clock_t t_start, t_stop;
// float seconds;
// t_start = clock();
//
// int frq[DMAX];
//int i, x;
//
//
//
// cin >> n;
//srand(time(NULL));
// for (i = 0; i < n; i++) {
// cin >> x;
// frq[DMAX] = rand();
// x=frq[DMAX];
// cout << frq[DMAX] << '\t';
// frq[x]++;
// }
//
// for (i = 0; i < DMAX; i++)
// while (frq[i]--)
// cout << i << ' ';
//
// cout << '\n';
// t_stop = clock();
// seconds = ((float)(t_stop - t_start)) / CLOCKS_PER_SEC;
//
// cout <<endl<<"timp de executie:"<<" "<< seconds<<"s"<<endl;
//
// return 0;
//}

// #include <pch.h>
//#include <iostream>
//#include <cstdlib>
//#include <ctime>
//#define n 10
// #define m 10
// #define n 15

// using namespace std;

//int generator(int *max)


//{
// int v[num];
//
//
// return 0;
//}

//int max,i;
//int main()
//{
// clock_t t_start, t_stop;
// float seconds;
// t_start = clock();
//
// // char s[n];
// int v[n];
// srand(time(NULL));
// for (int i = 0; i < n; i++)
// {
// v[i] = rand();
// cout << v[i] << '\t';
//
//
// }
// for(int i=0;i<n;i++)
// {
// if(s[i]==' ')
//
// {v[j]=p;v[j+1]=i-p;j+=2;k=0;}
//
//else k++;
// }
// max=-999;
// for(int i=1;i<n;i++)
// {
// if(v[i]>max)
// max=v[i];
// }
// for(int i=0;i<n;i++)
// {
// if(max==v[i] || max==v[i+1])
// {i++;p++;}
// else i--;p--;
// }

// v[j]=p;v[j+1]=i-p;j++;k=0;
// for(int i=0;i<n;i++)
// {if(s[i]==' ') nr=nr+1;}
//
// max=0,jmax=0;
//
// for(int j=0;j<nr*1;j++)
// {
// if(v[j]>max)
// {
// jmax=v[j+1];
// max=v[j];
// }
// }
// for(int i=jmax;i<max+jmax;i++){
// if(jmax>max)
// jmax=max;
// }
//
//int max=0,i=0;
// while(n!=0)
// {
// if(n%10>max)
// max=n%10;
// v[i]=v[i]/10;
// }
//
// cout <<"\n"<< "numar maxim" << " " << max << endl;

// cout<<endl<<"introdu ordinul maximului="<<" ";


// cin >> i;
// cout<<endl << "maximul de ordinul "<<i<<" este=" <<v[i]<<endl;

// t_stop = clock();
// seconds = ((float)(t_stop - t_start)) / CLOCKS_PER_SEC;
//
// cout <<endl<<"timp de executie:"<<" "<< seconds<<"s"<<endl;
//
//
// return 0;
//}

// isacovalab1.cpp : This file contains the 'main' function. Program execution


begins and ends there.
//

// #include "pch.h"
//#include <iostream>
//#include <stdlib.h>
//#include <conio.h>
//#include <ctime>
//#define n 20
//#define m 20
//#define t 20
//
// using namespace std;
//
//int main()
//{
//
//
//
//
// /* int a[n], b[m], c[t];
// int k = 0;*/
// /*srand(time(NULL));
// for (int i = 0; i < n; i++)
// {
// a[i] = rand();
// cout << a[i] << '\t';
//
//
// }*/
//
//
// int a[100], b[100], c[200];
// int n, m, k = 0;
//
// cout << "n="; cin >> n;
// for (int i = 0; i < n; i++)
// cin >> a[i];
//
// cout << "m="; cin >> m;
//
// for (int j = 0; j < m; j++)
// cin >> b[j];
//
//
//
// int i = 0, j = 0;
//
// while (i < n && j < m)
// {
// if (a[i] < b[j])
// {
// c[k] = a[i];
// k++;
// i++;
// }
// else
// {
// c[k] = b[j];
// k++;
// j++;
//
// }
// }
// if (i <= n)
// {
// for (int p = i; p < n; p++)
// {
// c[k] = a[p];
// k++;
// }
// }
// if (j <= m)
// {
// for (int p = j; p < m; p++)
// {
// c[k] = b[p];
// k++;
// }
// }
// for(int p=0;p<k;p++)
// cout << c[p] <<" ";
//
//
// return 0;
// }

//void asterisc(int nr)


//{
//
// for(int i=0;i<nr;i++)
// cout<<" * ";
//// return nr;
//}
//int main()
//{
// int v[40];
// asterisc(5);
// return 0;
//}

#include <iostream>
#include <cstdlib>

using namespace std;

// Functie pentru a introduce valoarea maxima in sir


int obtineMax(int vector[], int n)
{
int max = vector[0];
for (int i = 1; i < n; i++)
if (vector[i] > max)
max = vector[i];
return max;
}
//Functie pentru a numara si a sorta sirul
void countSort(int vector[], int n, int exp)
{
int output[n];
int i=0, numara[10] = {0};
//Stocheaza numarul de aparitii
for (i = 0; i < n; i++)
numara[(vector[i] / exp) % 10]++;
//Shimba numarul numara[i] astfel incat acesta contine acum pozitia reala a lui
output[]
for (i = 1; i < 10; i++)
numara[i] += numara[i - 1]; //Construieste sirul de tip output
for (i = n - 1; i >= 0; i--)
{
output[numara[(vector[i] / exp) % 10] - 1] = vector[i];
numara[(vector[i] / exp) % 10]--;
}
//Copiaza sirul de tip output in vector[]
for (i = 0; i < n; i++)
vector[i] = output[i];
}
// Sorteaza vector[] de dimensiuni n folosind Radix Sort
void radixsort(int vector[], int n)
{

//Cauta numarul maxim


int m = obtineMax(vector, n);
//Numara sortarea pentru fiecare valoare
for (int exp = 1; m / exp > 0; exp *= 10)
countSort(vector, n, exp);
}
//Programul pentru a testa functia de mai sus

int main()
{
int vector[] = {17, 15, 705, 40, 92, 29, 3, 67};
int n = sizeof(vector)/sizeof(vector[0]),i=0;
radixsort(vector, n);
// for (int i = 0; i < n; i++)
// cout << vector[i] << " ";
cout<<"maximul este"<<" "<<vector[n-1];
cout<<endl<<"introdu ordinul="<<" ";
cin >> i;
cout << "maximul de ordinul "<<i<<" este=" << vector[n-
i*1]<<endl;
system("PAUSE");
}

You might also like