Pagini recente » Cod sursa (job #2411831) | Cod sursa (job #3283814) | Cod sursa (job #581671) | Cod sursa (job #121163) | Cod sursa (job #1990706)
#include <iostream>
#include <fstream>
#include <deque>
#include <vector>
#include <string>
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::deque<std::string> myL;
std::vector<std::string> res;
std::deque<std::string> *digits = new std::deque<std::string>[10];
myL.push_back(std::to_string(b));
int prev(b);
for (int i(0); i < nV - 1; i++) {
prev = (a * prev + b) % c;
myL.push_back(std::to_string(prev));
}
int p(1), len, aux, ind;
while (!myL.empty()) {
while (!myL.empty()) {
len = myL.front().size();
if (len < p) {
res.push_back(myL.front());
} else {
aux = len - p;
ind = myL.front()[aux] - '0';
digits[ind].push_back(myL.front());
}
myL.pop_front();
}
for (int i(0); i < 10; i++) {
while (!digits[i].empty()) {
myL.push_back(digits[i].front());
digits[i].pop_front();
}
}
p++;
}
std::cout << "here\n";
for (int i(0); i < nV; i += 10) {
fileOut << res[i] << ' ';
//std::cout << res[i] << ' ';
}
delete[] digits;
fileIn.close();
fileOut.close();
return 0;
}