Pagini recente » Cod sursa (job #489821) | Cod sursa (job #2930275) | Cod sursa (job #2272262) | Cod sursa (job #2871536) | Cod sursa (job #1990701)
#include <iostream>
#include <fstream>
#include <list>
#include <vector>
int main() {
std::ifstream fileIn("radixsort.in");
std::ofstream fileOut("radixsort.out");
int nV, a, b, c;
fileIn >> nV >> a >> b >> c;
//int nV(100), a(12), b(38), c(123);
std::list<int> myL;
std::vector<int> res;
std::list<int> *digits = new std::list<int>[10];
myL.push_back(b);
for (int i(0); i < nV - 1; i++) {
myL.push_back((a * myL.back() + b) % c);
//std::cout << myL.back() << '\n';
}
long long p(1);
int aux;
while (!myL.empty()) {
while (!myL.empty()) {
aux = myL.front();
myL.pop_front();
if (aux < p) {
res.push_back(aux);
} else {
digits[(aux / p) % 10].push_back(aux);
}
}
for (int i(0); i < 10; i++) {
while (!digits[i].empty()) {
myL.push_back(digits[i].front());
digits[i].pop_front();
}
}
p *= 10;
}
for (int i(0); i < nV; i += 10) {
fileOut << res[i] << ' ';
//std::cout << res[i] << ' ';
}
delete[] digits;
fileIn.close();
fileOut.close();
return 0;
}