Cod sursa(job #1080676)

Utilizator BionicMushroomFMI - Dumitrescu Tiberiu Alexandru BionicMushroom Data 12 ianuarie 2014 19:34:16
Problema Sortare prin comparare Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.66 kb
#include<fstream>
#include<queue>
using namespace std;

int main()
{
	queue <int> q[10];
	int *v, n, max = -1, ordin = 1;
	ifstream f("algsort.in");
	f >> n;
	v = new int[n];
	for (int i = 0; i < n; i++)
	{
		f >> v[i];
		if (v[i] > max)
			max = v[i];
	}
	f.close();
	while (max)
	{
		for (int i = 0; i < n; i++)
			q[(v[i] / ordin) % 10].push(v[i]);
		int j = 0;
		for (int i = 0; i < 10; i++)
		{
			while (!q[i].empty())
			{
				v[j] = q[i].front();
				q[i].pop();
				j++;
			}
		}
		ordin *= 10;
		max /= 10;
	}
	ofstream g("algsort.out");
	for (int i = 0; i < n; i++)
		g << v[i] << ' ';
	delete[] v;
	g.close();
	return 0;
}